Question
Design a Ship class that has the following class members: A field for the name of the ship A field for the year the ship
Design aShipclass that has the following class members:
A field for the name of the ship
A field for the year the ship was built
A constructor
Appropriate accessors and mutators
toString method that displays the ships name and the year it was built
Design aCruiseShipclass the inherits from the Ship class. Include the following members:
A field for the max number of passengers
A constructor
Appropriate accessors and mutators
toString method that overrides the Ship toString method. The method should display the ship name and the max number of passengers
Design aCargoShipclass that inherits from the Ship class. Include the following members:
A field for cargo capacity (tons)
A constructor
Appropriate accessors and mutators
toString method that overrides the base class. The method should display ships name and cargo capacity.
Demonstrate these classes in a program that creates two objects from each class and stores them in an ArrayList of Ship objects. Use the following information:
Ship- NSU Vic , 1884
Ship- NSU Column, 1902
Cruise Ship- Java Queen 1, 2003, 450
Cruise Ship- CIS Minnow, 2010, 250
Cargo Ship- Demon 1, 1999, 7000
Cargo Ship- Demon 2, 1993, 10000
Step through the ArrayList and call the toString method for each object.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started