1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Margaret [11]
3 years ago
13

Design a Ship class with the following members:

Computers and Technology
1 answer:
Bess [88]3 years ago
8 0

Answer:

See Explaination

Explanation:

// Ship.java

public class Ship {

//field to store the name of the ship

private String name;

// filed to store the built on date as string

private String builtOn;

// constructor for ship takes name and built on date as argument

public Ship(String name, String builtOn) {

this.name = name;

this.builtOn = builtOn;

}

// getter to get the name of the ship

public String getName() {

return name;

}

// setter to set the name of the ship

public void setName(String name) {

this.name = name;

}

// getter method to get the built on date of the ship

public String getBuiltOn() {

return builtOn;

}

// setter method to set the built on date of the ship

public void setBuiltOn(String builtOn) {

this.builtOn = builtOn;

}

// to string method to print the ship as as string

public String toString() {

return "Ship [name=" + name + ", builtOn=" + builtOn + "]";

}

}

// CruiseShip.java

public class CruiseShip extends Ship {

// field to store the max number of passenger in the ship

private int maxNumberOfPassenger;

// constructor for cruise ship takes name , builton date and max number of passenger as argument

public CruiseShip(String name, String builtOn, int maxNumberOfPassenger) {

super(name, builtOn);

this.maxNumberOfPassenger = maxNumberOfPassenger;

}

// getter method to get the maximum number of passenger in the ship

public int getMaxNumberOfPassenger() {

return maxNumberOfPassenger;

}

// setter mehtod to set the maximum number of passenger in the ship

public void setMaxNumberOfPassenger(int maxNumberOfPassenger) {

this.maxNumberOfPassenger = maxNumberOfPassenger;

}

// to string method to print the cruise ship as string

atOverride //replace the at with at symbol

public String toString() {

return (super.toString() + ", " + "CruiseShip [maxNumberOfPassenger=" + maxNumberOfPassenger + "]");

}

}

// CargoShip.java

public class CargoShip extends Ship{

// field to store the capacity of cargo ship

private int cargoCapacity;

// constructor for cargo ship takes name , builton date and capacity as argumnet

public CargoShip(String name, String builtOn, int cargoCapacity) {

super(name, builtOn);

this.cargoCapacity = cargoCapacity;

}

// getter method to get the capacity of cargo ship

public int getCargoCapacity() {

return cargoCapacity;

}

// setter method to set the capacity of cargo ship

public void setCargoCapacity(int cargoCapacity) {

this.cargoCapacity = cargoCapacity;

}

// to string mehtod to print the cargo ship object as string

atOverride // replace at with its symbol

public String toString() {

return (super.toString() + ", " + "CargoShip [cargoCapacity=" + cargoCapacity + " tonnage]");

}

}

// Test.java

import java.util.ArrayList;

import java.util.List;

public class Test {

// driver mehtod to test declared class

public static void main(String args[]){

// declare arraylist of ship to store the ships

List<Ship> ships = new ArrayList<Ship>();

// adding the ship into the arraylist

ships.add(new Ship("ShipA", "04/04/2018"));

ships.add(new Ship("ShipB","05/04/2018"));

ships.add(new CruiseShip("CruiseShipA", "03/04/2018", 14));

ships.add(new CruiseShip("CruiseShipB", "04/04/2018", 24));

ships.add(new CargoShip("CargoShipA", "02/04/2018", 40));

ships.add(new CargoShip("CargoShipB", "04/04/2018", 12));

// printing the ships by iterating over the array list of ships

for (int i = 0; i < ships.size(); i++){

System.out.println(ships.get(i));

}

}

You might be interested in
Your principal has hired you to design a drone that can monitor students in the hallways. Before you brainstorm design ideas, yo
torisob [31]
It’s gonna be Answer B because all the other answers just sound silly
8 0
3 years ago
Read 2 more answers
your friend's parent's are worried about going over their budget for the month. Which expense would you suggest is NOT a need?
Lorico [155]

Answer:

A possible expense that are not a need are entertainment.

I hope this helped!

4 0
3 years ago
Why is statistics important?
kenny6666 [7]

The answer is A.؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜

7 0
3 years ago
An example of software is a _____.<br><br> spreadsheet<br> mouse<br> track ball<br> printer
algol13

An example of software is a spreadsheet :)

8 0
3 years ago
What is htc one mseven​
Tamiku [17]

"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

8 0
3 years ago
Other questions:
  • To create an individual version of a slide, you would click
    9·1 answer
  • What does the Chart Elements option allow you to change? A. Values B. Color C. Style D. Axis titles
    13·1 answer
  • What can search the Internet and select elements based on important words?
    6·2 answers
  • The Internet may best be compared to a/an
    11·1 answer
  • Which type of NAC agent will be used during the posture assessment before allowing access to the VPN users?
    9·1 answer
  • What is a Slide Master? A. the placeholder used to insert objects B. the sequence of slides in a presentation C. the default des
    14·1 answer
  • What is the term for a set of actions carried out on inputs?
    7·1 answer
  • Hich of these statements is a value statement?
    14·2 answers
  • If a switch needs to send information to other switches in the network it would send out a ___________.
    7·2 answers
  • 20 POINTS! Which music making software is better? Ableton Live or Logic Pro? Name the advantages and disadvantages of each one!
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!