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
Define the types of objects that can be stored in active directory, such as user or computer accounts.
nevsk [136]
<span>Schema classes define all objects that AD can handle.</span>
8 0
4 years ago
The three tasks within data harmonization, namely: data consolidation, data cleansing, and data formatting use techniques called
-BARSIC- [3]

The three tasks within data harmonization, namely: data consolidation, data cleansing, and data formatting use techniques called harmonization rules that implement those tasks -The statement is true

Explanation:

Data harmonization refers to the process of combining the data of varying files and formats ,name conventions and columns and transforming the same into one data set.

Data harmonization refers to the process of integrating multiple data source into a single data set.

By adopting the Data harmonization technique we can reduce the problem of redundant data and conflicting standard

The name harmonization is an analogy to the process to harmonizing discordant music.

The goal of data harmonization is to find commonalities, identify critical data that need to be retained, and then provide a common standard.

6 0
4 years ago
A jackhammer uses pressurized gas to transmit force to the hammer bit. What type of mechanical system is it?
Nadya [2.5K]
This is a pneumatic system
7 0
3 years ago
In the context of the database design process, the conceptual design step that defines the fragmentation and allocation strategy
cluponka [151]
In the context of the database design process, the conceptual design step that defines the  fragmentation and allocation strategy is the database design flashcards. The distributed data base design problem is presented that involve a development of a global model ; a fragmentation and a  data allocation.
4 0
3 years ago
What is the correct order of the phases of the software development process?
Damm [24]
Known as the 'software development life cycle,' these six steps include planning, analysis, design, development & implementation, testing & deployment and maintenance. Let's study each of these steps to know how the perfect software is developed.
8 0
3 years ago
Other questions:
  • Someone please help fast! I’m taking the test rn and I don’t understand this!!!!!!
    15·1 answer
  • What are three ways you cite evedince
    5·2 answers
  • When setting up a file system that is intended to be shared among several users, it is good practice to configure permissions so
    5·1 answer
  • Imagine that a company is having trouble assuring its bills are paid on time. An effective solution will
    13·1 answer
  • Kathi, the owner of Klothes for Kats, is excited about the launch of her first Local Catalog ad. She remembers there are a few d
    6·1 answer
  • Who Keeps Reporting My questions<br><br> Please Be Honest Lying Isnt Nice
    15·1 answer
  • Ten examples of an interpreter
    8·1 answer
  • Can anyone help???
    6·2 answers
  • Choose the correct term to complete the sentence.
    14·1 answer
  • What is the value stored in the variable myNum after the following assignment statement executes? myNum = 23 % 5
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!