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
Johnathan was assigned to complete a project with three other people. What benefit will he get from working with the team?
Lina20 [59]

Answer:

2.

Explanation:

working with other people can increase ones creativity

4 0
3 years ago
10. This transition level allows emergency managers to study the social media medium and language used in order to
Stells [14]

Answer:

The Level 1 Monitor

Explanation:

From the given question, the Level 1 Monitor is the correct answer.

The Level 1 Monitor allows or permits emergency managers to study the social media medium and language used in order to better understand the workings of the service.

8 0
3 years ago
The __________ algorithm takes the ciphertext and the secret key and produces the original plaintext
Bad White [126]
The answer is decryption
8 0
3 years ago
Hi tech was signed in what year
sleet_krkn [62]
It was signed in 2009..!!
hope its right!
6 0
3 years ago
Write the steps for mail merge and formation of documents.
denpristay [2]

Answer:  

The steps for mail merge and formation of documents are:

Mail merge are used for simplifying the repetitive document and several tasks. Mail merge is the process for creating many documents at once that contain identical formatting, graphics and layout text. Basically, it consist of two files, the data source and the mail document.

  • In order to run the mail merge, the first step is that create the document name as mail merge and if the TABLE were on a separate page then simply create  it as DATA SOURCE by clicking on OPEN button.
  • Then, last step is to hit the merge into the new document button on the tool bar, which is the fourth to last button on far right end of the tool bar.
8 0
4 years ago
Other questions:
  • What does microsoft recommend for large organizations requiring desktop virtualization for many clients? quizlewt?
    10·1 answer
  • Qazwsxedcrfvtgbyhnujmikolp. In which direction on the keyboard did I type in?
    14·2 answers
  • The picture that graphically represents the items you use in Windows is called a/an
    15·1 answer
  • Which of the following has the honor of the first robot-human handshake in space?
    10·1 answer
  • Which loan type requires you to make loan payments while you’re attending school?
    7·2 answers
  • if you wanted to predict the value of the y variable when the x variable is 15, you would be _____ the data. correlating extrapo
    14·2 answers
  • Stuart wants to delete some text from a slide. What should Stuart do?
    8·1 answer
  • Which expression is equivalent to 3x + 3x + 3x?<br><br> From Performance Matters
    11·2 answers
  • Imagine that you need to prepare for three end-of-term tests. What steps will you take to make sure your study time is well spen
    5·1 answer
  • For the function below, list 4 ordered pairs for that function.<br> y = 3x + 1
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!