Lab 1: Basic Concept of Classes: SHARON LAWAI (2021132273)
Lab 1: Basic Concept of Classes: SHARON LAWAI (2021132273)
Lab 1: Basic Concept of Classes: SHARON LAWAI (2021132273)
Prelab Activities
Answer the following questions in the space provided. Your answers should be concise
as possible.
1. What is an object?
• Object can be defined as entity that has behavior, state and identity.
4. List down all data members for the above program statement.
• noBill
• price
• no_bill
• m
• y
MMR@FSKM2021
CSC584 Enterprise Programming
1. The following defines class Art, with no argument constructor that sets the art’s name to an
empty String and the price to 0.00 and a toArtString method that returns a String
containing the art’s name and its price.
• Compilation error. Java cannot run as there is no return data type in public
toArtString().
• import java.text.*;
public class Art {
MMR@FSKM2021
CSC584 Enterprise Programming
• Compilation error. Both constructors have the same name and parameter. It is
redundant.
• public Art(double price) {
this.name = "This product";
this.price = price;
}
MMR@FSKM2021
CSC584 Enterprise Programming
Lab Exercise
Solve the problem given.
• Input:
MMR@FSKM2021
CSC584 Enterprise Programming
• Output:
MMR@FSKM2021
CSC584 Enterprise Programming
a. Three double data fields named side1, side2 and side3 that specify the three sides of the
triangle. The default values are 1 for all the sides.
public Triangle () {
side1 = 1;
side2 = 1;
side3 = 1;
}
d. The accessor and mutator methods for all the data member.
//accessor
public double getSide1() {
return side1;
}
MMR@FSKM2021
CSC584 Enterprise Programming
//mutator
public void setSide1 (double s1) {
Side1 = s1;
}
Write a main program that creates two Triangle objects. Assign sides 4, 5 and 6 to the first
object and 1.5, 2.5 and 3.5 to the second object. Display the properties of both objects and find
their areas and perimeters.
MMR@FSKM2021
CSC584 Enterprise Programming
Postlab Exercise
MMR@FSKM2021
CSC584 Enterprise Programming
//Accessor
public double getStudentName () {
return studentName;
}
MMR@FSKM2021
CSC584 Enterprise Programming
d. A processor method named calculateFinalMarks(). This method will calculate and return
final marks of student based on the following formula.
return finalMarks;
e. Write a main method that create four objects of student and assigned each of them with
values for each data members. Then display the student name, student ID and final
marks for all the students objects
public static void main (String [ ] args) {
Student stu1 = new Student (“Sharon”, “2021132273”, “CS240”, 80, 90, 95);
Student stu2 = new Student (“David”, “2021132274”, “CS230”, 81, 91, 96);
Student stu3 = new Student (“Siti”, “2021132275”, “CS110”, 70, 80, 85);
Student stu4 = new Student (“Arnold“, “2021132276”, “AS110”, 70, 80, 85);
}
MMR@FSKM2021