Question: Please help me with this, to write TestJunit for all these classes . Thank you! CargoShip.java /** The CargoShip class stores data about a ship

Please help me with this, to write TestJunit for all these classes . Thank you!

CargoShip.java

/** The CargoShip class stores data about a ship that is a cargo ship for the Ship, CruiseShip, and CargoShip Classes programming challenge. */

public class CargoShip extends Ship { private int tonnage; // Cargo tonnage

/** Constructor @param n The ship's name. @param y The year the ship was build. @param t The cargo tonnage. */

CargoShip(String n, String y, int t) { // Call the superclass constructor (Ship), // passing the name and year as arguments. super(n, y); // Set tonnage. tonnage = t; } /** setTonnage method @param t The maximum cargo tonnage. */ public void setTonnage(int t) { tonnage = t; } /** getTonnage method @return The ship's cargo capacity in tons. */ public int getTonnage() { return tonnage; }

/** toString method @return A string indicating the ship's name and the cargo capacity. */ public String toString() { return "Name: " + getName() + " Cargo capacity: " + tonnage + " tons"; } }

CruiseShip.java

/** The CruiseShip class stores data about a ship that is a cruise ship for the Ship, CruiseShip, and CargoShip Classes programming challenge. */

public class CruiseShip extends Ship { private int passengers; // Maximum number of passengers

/** Constructor @param n The ship's name. @param y The year the ship was build. @param p The maximum number of passengers. */

CruiseShip(String n, String y, int p) { // Call the superclass constructor (Ship), // passing the name and year as arguments. super(n, y); // Set passengers. passengers = p; } /** setPassengers method @param p The maximum number of passengers. */ public void setPassengers(int p) { passengers = p; } /** getPassengers method @return The ship's maximum number of passengers. */ public int getPassengers() { return passengers; }

/** toString method @return A string indicating the ship's name and the maximum number of passengers. */ public String toString() { return "Name: " + getName() + " Maximum passengers: " + passengers; } }

Ship.java

/** The Ship class stores data about a ship for the Ship, CruiseShip, and CargoShip Classes programming challenge. */

public class Ship { private String name; // Ship name private String yearBuilt; // Year it was built /** Constructor @param n The ship's name. @param y The year the ship was build. */ public Ship(String n, String y) { name = n; yearBuilt = y; } /** setName method @param n The ship's name. */ public void setName(String n) { name = n; }

/** setYearBuilt method @param y The year the ship was built. */ public void setYearBuilt(String y) { yearBuilt = y; }

/** getName method @return The ship's name. */ public String getName() { return name; }

/** getYearBuilt method @return The year the ship was built. */ public String getYearBuilt() { return yearBuilt; } /** toString method @return A string indicating the ship's name and the year it was built. */ public String toString() { return "Name: " + name + " Year built: " + yearBuilt; } }

ShipDemo.java

/** This program demonstrates a solution to the Ship, CruiseShip, and CargoShip Classes programming challenge. */

public class ShipDemo { public static void main(String[] args) { // Constant for the number of ships. final int NUM_SHIPS = 3; // Create an array of Ship references. Ship[] ships = new Ship[NUM_SHIPS]; // Assign Ship objects to the array elements. ships[0] = new Ship("Lolipop", "1960"); ships[1] = new CruiseShip("Disney Magic", "1998", 2400); ships[2] = new CargoShip("Black Pearl", "1800", 50000); // Call each object's toString method. for (int index = 0; index < 3; index++) { System.out.println(ships[index]); System.out.println("----------------------------"); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!