Cargo Ships This question involves cargo ships that carry a specific number of cargo containers. Each ship has a maximum number of cargo containers that it can hold and a current number of cargo containers that it is holding. You can see more details in the Ship class that is provided for you. Part A For part A, you will be completing the nextToUnload() method. This takes no input and returns a Ship from the ships instance variable that has the highest percentage of its cargo hold filled (as measured by current hold / capacity). If two ships have the same percentage, then it should return the first ship with that percentage. If all of the ships in the ships array are empty (ie. no cargo), the method should return null. Part B For part B, you will complete the two unloadShip methods. The first method takes a Ship object and unloads all of the cargo from that ship. The second method takes a Ship and an int and unloads the specified number of containers from the ship. If the number of containers is more than what is currently on the ship, it should only unload the number that are on the ship. In both cases, the methods should update the Ship object to set the currentHold to reflect the containers unloaded, then return the number of containers that were unloaded from the ship. public class Yard { private Ship[] ships; public Yard(Ship[] ships){ this.ships = ships; } /* * precondition: ships array * length is greater than 0 */ public Ship nextToUnload(){ /* Paste your code from Part A */ } public int unloadShip(Ship ship){ /* Paste your code from part B */ } public int unloadShip(Ship ship, int amount){ /* Paste your code from part B */ } }       public class Ship { private int currentHold; private int capacity; public Ship(int currentHold, int capacity){ this.currentHold = currentHold; this.capacity = capacity; } // Returns the number of containers currently // loaded on the ship public int getCurrentHold() { return currentHold; } /* * precondition: all ships will have a * currentHold >= 0 */ // Sets the number of containers currently // loaded on the ship public void setCurrentHold(int currentHold) { this.currentHold = currentHold; } /* * precondition: all ships will have a * capacity > 0 */ // Returns the total number of containers the // ship can hold public int getCapacity() { return capacity; } }     public class ShipTester { public static void main(String[] args) { // Add code if you would like to test your methods } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Cargo Ships

This question involves cargo ships that carry a specific number of cargo containers. Each ship has a maximum number of cargo containers that it can hold and a current number of cargo containers that it is holding. You can see more details in the Ship class that is provided for you.

Part A

For part A, you will be completing the nextToUnload() method. This takes no input and returns a Ship from the ships instance variable that has the highest percentage of its cargo hold filled (as measured by current hold / capacity). If two ships have the same percentage, then it should return the first ship with that percentage.

If all of the ships in the ships array are empty (ie. no cargo), the method should return null.

Part B

For part B, you will complete the two unloadShip methods. The first method takes a Ship object and unloads all of the cargo from that ship. The second method takes a Ship and an int and unloads the specified number of containers from the ship. If the number of containers is more than what is currently on the ship, it should only unload the number that are on the ship.

In both cases, the methods should update the Ship object to set the currentHold to reflect the containers unloaded, then return the number of containers that were unloaded from the ship.

public class Yard {

private Ship[] ships;

public Yard(Ship[] ships){
this.ships = ships;
}

/*
* precondition: ships array
* length is greater than 0
*/
public Ship nextToUnload(){
/* Paste your code from Part A */
}

public int unloadShip(Ship ship){
/* Paste your code from part B */
}

public int unloadShip(Ship ship, int amount){
/* Paste your code from part B */
}
}

 

 

 

public class Ship {

private int currentHold;
private int capacity;

public Ship(int currentHold, int capacity){
this.currentHold = currentHold;
this.capacity = capacity;
}

// Returns the number of containers currently
// loaded on the ship
public int getCurrentHold() {
return currentHold;
}

/*
* precondition: all ships will have a
* currentHold >= 0
*/
// Sets the number of containers currently
// loaded on the ship
public void setCurrentHold(int currentHold) {
this.currentHold = currentHold;
}

/*
* precondition: all ships will have a
* capacity > 0
*/
// Returns the total number of containers the
// ship can hold
public int getCapacity() {
return capacity;
}
}

 

 

public class ShipTester
{
public static void main(String[] args)
{

// Add code if you would like to test your methods

}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education