Question
Alright, so I have this program written out. Below is the code I have for my fully working Java program: (The original question that this
Alright, so I have this program written out. Below is the code I have for my fully working Java program: (The original question that this program is written for can be found here: https://www.chegg.com/homework-help/starting-out-with-java-6th-edition-chapter-10-problem-10PC-solution-9780133957068)
ShipArray Class:
public class ShipArray { public static void main(String[] args) { Ship[] ships=new Ship[3]; ships[0]=new Ship("INS vikrant", 1961); ships[1]=new CruiseShip("Titanic", 1909, 3547); ships[2]=new CargoShip("Columbo Express", 2005,200000); for (Ship ship : ships) { System.out.println(ship.toString()); } } }
Ship Class:
public class Ship { private String name; private int builtYear; public Ship(String name, int builtYear) { this.name=name; this.builtYear=builtYear; } public void setName(String name) { this.name=name; } public String getName() { return this.name; } public void setYear(int builtYear) { this.builtYear=builtYear; } public int getYear() { return builtYear; } @Override public String toString() { return "Ship Name: " + name + ", Built Year: " + builtYear; } }
CruiseShip Class:
public class CruiseShip extends Ship { private int numPassengers; public CruiseShip(String name, int builtYear, int numPassengers) { super(name, builtYear); this.numPassengers=numPassengers; } public void setPassengers(int numPassengers) { this.numPassengers=numPassengers; } public int getPassengers() { return numPassengers; } @Override public String toString() { return "Cruise Ship Name: " + getName() + ", Maximum number of passengers: " + numPassengers; } }
CargoShip Class:
public class CargoShip extends Ship { private int capacity; public CargoShip(String name, int builtYear, int capacity) { super(name, builtYear); this.capacity=capacity; } public void setCapacity(int capacity) { this.capacity=capacity; } public int getPassengers() { return capacity; } @Override public String toString() { return "Cargo Ship Name: " + getName() + ", Capacity (in tons): " + capacity; } }
So now, I need to do the following:
In addition to the requirements listed (which I have already completed), make sure that your classes contain copy constructors. The Cruise Ship class should have two subclasses, the River Cruise ship should have a maximum number of passengers of 400 and the Ocean Cruise ship should have a minimum number of passengers of at least 1000.
Can someone please help me write these subclasses for the CruiseShip class.. and please make sure they fully compile properly. Thank you so much!
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