Following completion of this task, students should be able to:
- Design and implement abstract class and interface
Question 1
Declare and implement an abstract class called Ship that has the following:
- An attribute to represent the name of the ship.
- An attribute to represent the year that the ship was built.
- A default constructor to initialize the attributes.
- Accessor methods and mutator methods for each of the attribute.
- An abstract method called displayDetails().
Declare and design a subclass of Ship called CruiseShip. The CruiseShip class should have the following: An additional attribute to keep the maximum number of passengers.
- A default constructor to initialize the attribute in CruiseShip as well as the Ship Accessor methods and mutator methods for its attribute.
- The displayDetails()method that will display all details from Ship and CruiseShip.
Declare and implement another subclass of Ship called CargoShip. The CargoShip class should have the following:
- An attribute to keep the cargo capacity in tonnage.
- A default constructor to initialize the attribute in CargoShip as well as the Ship Accessor methods and mutator methods for its attribute.
- The displayDetails()method that will display all details from Ship and CargoShip.
Write a main() method in another class called ShipApp. Declare an ArrayList<Ship> to keep several CruiseShip and CargoShip objects. Use a simple menu to allow the user to
- add either a CruiseShip or a CargoShip
- edit either the number of passengers for a CruiseShip or the cargo capacity for the CargoShip
- display all the objects in the ArrayList.
Reviews
There are no reviews yet.