ITPROG3L - Lab Exercise 4 (Creating Classes and Objects)
ITPROG3L - Lab Exercise 4 (Creating Classes and Objects)
ITPROG3L
(Object Oriented Programming)
EXERCISE
4
Creating Classes and Objects
<STUDENT NAME>
<SECTION>
<DATE>
I. Objectives:
At the end of the experiment, students must be able to:
Cognitive
a) understand how object-oriented programming and some of its concepts
b) understand the classes and objects
c) understand how instance variables/methods and class(static) variables/methods are being
used
Psychomotor:
a) construct a program using classes and objects
b) compile and debug the error of the program
Affective
a) appreciate the concept behind this experiment
II. BACKGROUND INFORMATION
A class is a considered as the center of Object Oriented Programming methodology and
defines the abstract characteristics of a thing (object), including the thing's characteristics (its
attributes, fields or properties) and the thing's behaviors (the things it can do, or methods,
operations or features). An object is an instantiation of a class.
In a way, a class and its objects have the relationship of a data type and variables. A class is
simply a template for holding objects. It is abstract but objects are real.
Classes are generally declared using the keyword class.
III. EXPERIMENTAL PROCEDURE:
Exercise #01:
(Car.java)
(CarTest.java)
Write a test class for the Car class above. You are required to do the followings:
A. Create an object of type Car.
B. Assign any valid values to the instance variables of the object created in A.
C. Use the method getPriceAfterUse on the object created in A then output the result to the
screen.
D. Use the method updateMilage on the object created in A by passing a valid value.
E. Do part C again.
F. Use the method outputDetails on the object created in A.
Exercise #3 (a):
(Student.java)
Implement a Student class with the following fields, constructors and methods:
Fields (All should be private):
name;
totalScore;
numOfQuizzes;
Constructor:
public Student(String name)
Methods:
public String getName()
public double getAverage()
taken.
//this
should
the
students
name
and
(StudentTest.java)
Write an application StudentTest that reads a student name and use the Student
class to create a Student object. Then read the scores of the student in 3 quizzes
and add each to the totalScore of the student using the addQuiz method, then
print the student object.
Sample Output
Enter Student Name: Jared
Enter Quiz 01 Score for Jared: 10
Enter Quiz 02 Score for Jared: 8
Enter Quiz 03 Score for Jared: 9
Student Name : Jared
Average Score: 9.0