Question: Java Programming Is this class diagram and program correct for the below prompt? He did not give any expected output or requirement. Also does the
Java Programming
Is this class diagram and program correct for the below prompt? He did not give any expected output or requirement.
Also does the code below meet the following standards?
CODING STANDARDS
All classes should be public
Every class should have a print method
Every class must have a default constructor
Use packages for every lab staring lab 5
all properties (instance or static) should be declared private
class name must start with uppercase
must have public instance methods
main() should be in its own class and can have method for input or for automating testing
one class per .java file
must add a default constructor in each class that is used for creating objects
structure of class
o Instance and static variables
o Constructors
o Instance methods
o Static methods
_________________________________________________________________________________________________
PROMPT
Exercise 2
Design a Ship, CargoShip and CruiseShip class being mindful of behavior of each. Demonstrate the classes in a program that has a Ship array. Assign various Ships, CruiseShip and CargoShip to the array elements.
CargoShip and CruiseShip are a child of Ship class.
_________________________________________________________________________________________________
import ships.CargoShip;
import ships.CruiseShip;
import ships.Ship;
public class Driver
{
public static void main(String[] args)
{
// Demonstrate the classes
//program that has a Shiparray.
// Assign objects to the array elements.
Ship[] shipArray = new Ship[8];
shipArray[0] = new Ship("USS Typhoon", 2000);
shipArray[1] = new CruiseShip("HMS Queen Victoria", 2001, 200);
shipArray[2] = new CruiseShip("HMS Queen Elizabeth", 1999, 300);
shipArray[3] = new Ship("Mustang", 2001);
shipArray[4] = new Ship("Camaro", 2001);
shipArray[5] = new Ship("Muskogee", 2000);
shipArray[6] = new CargoShip("Leviathan", 2006, 100);
shipArray[7] = new CargoShip("Enterprise", 2004, 350);
for (Ship ship : shipArray)
{
System.out.println(ship.toString());
}
}
}
_____________________________________________________________________________________________
package ships;
public class Ship
{
private String shipName;
private int year;
public Ship(String shipName, int year)
{
this.shipName = shipName;
this.year = year;
}
public String getShipName()
{
return shipName;
}
public void setShipName(String shipName)
{
this.shipName = shipName;
}
public int getYear()
{
return year;
}
public void setYear(int year)
{
this.year = year;
}
@Override
public String toString()
{
return this.getShipName() + " built in " + this.getYear();
}
}
________________________________________________________________________________________________
package ships;
public class CruiseShip extends Ship
{
private int maxPass;
public CruiseShip(String shipName, int year, int maxPass)
{
super(shipName, year);
this.maxPass = maxPass;
}
public int getMaxPass()
{
return maxPass;
}
public void setMaxPass(int maxPass)
{
this.maxPass = maxPass;
}
@Override
public String toString()
{
return this.getShipName() + " holds " + this.getMaxPass() + " passengers";
}
}
______________________________________________________________________________________________
package ships;
public class CargoShip extends Ship
{
private int capacity;
public CargoShip(String shipName, int year, int capacity)
{
super(shipName, year);
this.capacity = capacity;
}
public int getCapacity()
{
return capacity;
}
public void setCapacity(int capacity)
{
this.capacity = capacity;
}
@Override
public String toString()
{
return this.getShipName() + " holds " + this.getCapacity() + " tons";
}
}

CARGOSHIP ships SHIP ships -shipName: String cll +CargoShip(String shipName,.int year.int capacity) +getCapacity0: int +setCapacity(int capacity): void +string toString0 +Ship(String shipName, int year) +getShipName0 +setShipName(string shipName): void +getYear0 +set Year (int year) : void +String toString0 ISESHIP ships maxPass: int +CruiseShip(String shipName,int year, int maxPass) +getMaxPass0: int +setMaxPass (int maxPass): void +String toString0 RIVER1 LEGEND Public Private Protected Package +main(Stringl]): void +Ship[] shipArray
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
