Answered step by step
Verified Expert Solution
Link Copied!

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).

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago