Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CSI247: Lab 1 – More Objects and Inheritance

At the end of this lab you should be able to:


 Create an abstract class
 Inherit from the abstract class
 Create an interface
 Inherit from and interface
 Implement an interface
 Implement the Comparable interface
 Overriding super class method.
 Follow proper java project folder structure and compile from the command line.

Figure 1: UML Diagram of the class hierarchy.

The UML diagram above shows a hierarchy of classes. Implement this in java. Follow the folder
structure shown in the lecture video on moodle. In the diagram above, the solid line shows class
inheritance while the dotted one shows interface inheritance. All the classes should have the default
constructor and the non default constructor as well as the getters and setters for the instance
variables. The concrete classes should also override the toString() and equals() methods. The root
project folder should be called lab1.

Person Class
This class is abstract and will be in the package directory
“lab1. person”. The method walk() is also abstract. The
method should just print the statement “I am walking as a
student/teacher”. The name property should be declared
protected.
Comparable Interface
This is a comparable from java.lang package so no need to
create the interface. Just implement or extend it where
necessary.
Learner Interface
This interface has one method called “boolean
isGoodLearner()”. The method should use the properties
of the implementing class to return true or false for
whether the learner is good or not. The details of how you
determine this is entirely up to you. This interface should
Figure 2: The folder structure after be created in the package “lab1.person.learner”.
compiling.
Student Class
This class is meant to model the student object and should be in the package “lab1.student”.
Teacher Class
The teacher class should be in the package “lab1.teacher”.
Tester Class
In this class, which should be in the “lab1” package, you should demonstrate the following:
 Polymophism with all subclasses (For both the abstract class and the interfaces)
 Narrowing and widening conversions.
 Demonstrate the limitations of widening conversion.
 How you can get ClassCastException
 Comparison of objects using both compareTo and equals() methods.

You might also like