Starting from:

$30

CSIT121-Lab 2 Design and Implement Classes using Inheritance Solved

Following completion of this task, students should be able to:

 

§ Design and implement classes using inheritance

 Question 1
Design and implement a class called Vehicle that has a registration number, manufacturer’s name (type String), and the engine (type String). Provide a default constructor to initialize all attributes as well as the set method for each attributes. Implement also a method to display the Vehicle details.

 

Next, create two subclasses that inherit from Vehicle. The first subclass is called Truck. A Truck class has additional properties that includes the load capacity in tons (type double) and a towing capacity in tons (type double). Provide a default constructor for this class that will initialize its attributes as well as the superclass attributes. Provide also the set methods for its attributes and another display method to overload/override the one defined in the superclass so that it will also display the Truck’s attributes as well as the Vehicle’s.

 

The second subclass is called Aircraft. An Aircraft object should have as additional attributes the type of aircraft (cargo, passenger, etc), and the capacity (num of passengers, baggage, cargo, or fuel). Also provide a default constructor, set methods, and display methods similar to the Truck’s class.

 

Write another class that contain a main() method to test your classes. Your main() method should create an

ArrayList<Vehicle as a general type. Create several Truck and Aircraft objects and store them in the ArrayList. Use the set methods to change the attributes for each objects and display all object’s details on the screen.

More products