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
Nora has shared a document with others, and she needs to be able to easily identify when others are modifying the
Lilit [14]

Answer:

What is the purpose of the wordart text effect called Transform?

What is the purpose of the WordArt text effect called Transform? It adjusts the shape of the text. Why is it helpful to combine documents when there are multiple reviewers? This allows users to view color-coded changes from several reviewers in one document.

Explanation:

8 0
3 years ago
Bob flys a drone which has a 20 megapixel camera attached, what is the definition of "megapixel in this context? Why does it mat
Verizon [17]

Answer:

megapixel refers to the unit of resolution i.e. one million

Explanation:

Interestingly the higher the pixels does not mean higher quality of image, it's more about the camera and it's sensor.

I am a photographer and a licensed drone pilot and have researched the subject to help with camera choice, both DSLR and drone.

5 0
3 years ago
Write a function called getRowTotal. This function should accept a two-dimensional int array as its first parameter (the array h
garik1379 [7]

Answer:

The solution is implemented using C++

int getRowTotal(int a[][5], int row) {

  int sum = 0;

  for(int i =0;i<5;i++)

  {

      sum += a[row][i];

  }

  return sum;

}

Explanation:

This defines the getRow function and the parameters are arr (the 2 d array) and row and integer variable

int getRowTotal(int arr[][5], int row) {

This defines and initializes sum to 0

  int sum = 0;

This iterates through the row and adds the row items

<em>   for(int i =0;i<5;i++)    { </em>

<em>       sum += arr[row][i]; </em>

<em>   } </em>

This returns the calculated sum

  return sum;

}

8 0
3 years ago
Personal digital assistants are hand held devices that serve as personal information managers. What is another term used to refe
olganol [36]

Answer:

Pocket Computers

Explanation:

6 0
3 years ago
Read 2 more answers
Hardy doesn't have access to a work template, which is on the network server. What should he do?
BabaBlast [244]

Answer:

Allow access.

Explanation:

Network server is a type of central repository (file server), where computers connected to it can access files stored in the repository. There can be other types of network server, besides file server, like printer server.

Network server are usually not available over the internet and require users to connect to a local network (intranet), in order to access it.

The server is managed by an administrator. One of the jobs of the administrator is to password protect and/or add users to the server.

4 0
4 years ago
Other questions:
  • How does FTP work? explain in brief.
    8·1 answer
  • In an input file, what maintains the location of the next item that will be read from the file?
    11·1 answer
  • Nina wants to create a digital backup of her holiday videos to view later. What two of these devices could she use?
    11·2 answers
  • Which of the following is the fundamental unit of the virtualized client in an IaaS deployment? a)Workload b)Workspace c)Work un
    8·1 answer
  • The bus width and bus speed together determine the bus's ____ or bandwidth; that is, the amount of data that can be transferred
    6·1 answer
  • At each layer of the OSI model, data is appended to the original message and then sent on to the next lower layer. What is this
    10·1 answer
  • Which of the following actions would not reduce software piracy? reducing the cost of software. offering downloads of software.
    12·2 answers
  • What is an input to the Program Increment Planning process that highlights how Product Management plans to accomplish the Vision
    15·1 answer
  • What is the best use of network in homes
    15·2 answers
  • When is the new season of legacies coming out on netflix
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!