Question: In this assignment you are to create a parent class (Ship), two child classes (CruiseShip and CargoShip) and a class that will demonstrate the three
In this assignment you are to create a parent class (Ship), two child classes (CruiseShip and CargoShip) and a class that will demonstrate the three classes developed. The variable and methods of each class are specified below.
Please note:
- The methods specified are similar to those we have developed in other exercises eg. toString methods return a string, equals methods return a boolean.
- The yearBuilt of a Ship must be 1900 - 2019 (inclusive), trap the user until a valid amount is input.
- The maximumPassengers of a CruiseShip must be > 0, trap the user until a valid amount is input.
- The cargoCapacity of a CargoShip must be > 0, trap the user until a valid amount is input.
Complete the following. Name the classes as detailed below.
- Design a Ship class:
- that has the following variables:
- private String name
- private int yearBuilt
- and the following methods
- Default constructor
- Constructor that accepts argument for name and yearBuilt
- Accessors (getters)
- Mutators (setters)
- A toString method
- An equals method
- that has the following variables:
- Design a CruiseShip class that extends the Ship class:
- that has the following variable:
- private int maximumPassengers
- and the following methods
- Default constructor
- Non-default constructor that accepts argument for maximumPassengers
- Accessors (getters)
- Mutators (setters)
- A toString method
- An equals method
- that has the following variable:
- Design a CargoShip class that extends the Ship class and has the following:
- that has the following variable:
- private int cargoCapacity
- and the following methods
- Default constructor
- Non-default constructor that accepts argument for cargoCapacity
- Accessors (getters)
- Mutators (setters)
- A toString method
- An equals method.
- that has the following variable:
- Write a class, name it Navy_yourInitials.java, where yourInitials represent your initials, in which you declare an array of 3 ships. Using input from the user create an instance of a Ship, a CruiseShip and a CargoShip and populate the array with those instances. After population of the array iterate through the array and have each instance call its toSting method and print the returned string.
- Submit all 4 files.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
