Answered step by step
Verified Expert Solution
Question
1 Approved Answer
10. Ship, cruiseship, and cargoship Classes Design a ship class that the following, members: . A field for the name of the ship (a string).
10. Ship, cruiseship, and cargoship Classes Design a ship class that the following, members: . A field for the name of the ship (a string). . A field for the year that the ship was built (a string). .A constructor and appropriate accessors and mutators. . A tostring method that displays the ship's name and the year it was built. Design a cruiseship class that extends the ship class. The cruiseship class should have the following members: .A field for the maximum number of passengers (an int). .A constructor and appropriate accessors and mutators. A toString method that overrides the toString method in the base class. The Cruiseship class's tostring method should display only the ship's name and the maxi- mum number of passengers. Design a cargoship class that extends the ship class. The cargoship class should have the following members: .A field for the cargo capacity in tonnage (an int). .A constructor and appropriate accessors and mutators. .A tostring method that overrides the tostring method in the base class. The cargoship class's tostring method should display only the ship's name and the ship's cargo capacity. Demonstrate the classes in a program that has a ship array. Assign various ship, Cruiseship, and cargoship objects to the array elements. The program should then step through the array, calling each object's tostring method. (See Code Listing 10-25 as an example.)
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