Home / Expert Answers / Computer Science / design-a-ship-class-with-the-following-members-a-field-for-the-name-of-the-ship-a-string-a-field-pa779

(Solved): Design a Ship class with the following members: A field for the name of the ship (a string). A field ...



Design a Ship class with the following members:

A field for the name of the ship (a string). A field for the year that the ship was built (an int). A no-arg constructor. A constructor that has name as the parameter. A constructor that has year as the parameter. A constructor that has name and year as the parameters. Accessors and mutators for name and year. A toString method that displays the ship's name and the year it was built.

Design a CruiseShip class that inherits from the Ship class:

The CruiseShip class should have the following members: A field for the maximum number of passengers (an int). Appropriate constructor, accessor and mutator. A toString method that overrides the toString method in the superclass class. Demonstrate the classes in a program. Ask the user to enter ship name, the year it was built and the passenger capacity. When the toString method is called, it should display ship name, year and number of passengers.

The following is an example of the output:

Ship Name:

Year Built:

Number of Passengers:

Note: There should be 3 separate java files, one each for the Ship, CruiseShip and Demo.



We have an Answer from Expert

View Expert Answer

Expert Answer


Solution: Ship.java : //Java class names Ship public class Ship { // members private String name;// name of the Ship private int year;// year in which Ship was built // A no-arg constructor public Ship() { } // A constructor that has name as the para
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe