Question
In java. Desgin a Ship class that has the following members: A field for the name of the ship (a string). A field for the
In java.
Desgin a Ship class that has the following members: A field for the name of the ship (a string). A field for the year that the ship was build (an int). A constructor and appropriate accessors and mutators. A toString method that displays the ship's name and the year it was built. An equals method to compare the data members of Ships. A canTravel method that always returns true. 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 field for the current number of passengers. 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 on the ship's name and the maximum number of passengers. An equals method to compare the data members of CruiseShips. A canTravel method that returns true if at least 80% of the passenger spots have been filled. Designe a CargoShip class that extends the Ship class. The CargoShip class should have the following members: A field for the cargo capacity in tonnage (a double). A field for the current amount of cargo in tonnage. 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. An equals method to compare the data members of CargoShips. A canTravel method that returns true if at least 90% of the cargo capacity has been filled. Part II: Demonstrate the classes in a program that has an array of Ships. Assign various Ship, CruiseShip, and CargoShip objects to the array elements. The program should step through the array and display the information about each array element, calling each object's toString method. The program should then calculate and print the number of ships that are ready to travel by calling the canTravel method for each object in the array. To think about: If a reference is of type Ship, it can contain a either a CruiseShip, Ship, or CargoShip object. When a method is in more than one class of the inheritance chain, does the system call the method in the references class or the one in the objects class?
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