Question: I need to make a program that simulates a dockyard. I need to simulate how the dockyard regularly has ships arriving with a lot of

I need to make a program that simulates a dockyard. I need to simulate how the dockyard regularly has ships arriving with a lot of containers that are offloaded into the dockyard and stored for later pick up. When a ship arrives, it has a manifest which lists all of the containers and the destination of each container. I need to offload the containers and store them in a staging location within the dockyard by destination city.

What I need help with:

  • there are interfaces defined container, a ship and a truck in the shipping package that I need implementation classes for
  • there is an interface defined for the dockyard that I will need to a class for, the dockyard needs to be able to store containers in different staging areas by destination city
  • I need an implementation for the ShippingProcessor class. There is a base class that provides default implementations the ShippingProcessor should leverage
  • all of the code I implement should be in a package name SOLUTION

Here are the starting points of what needs to be implemented:

package shipping;

public interface IContainer {

/**

* Returns the container's unique id.

*

* @return A string value indicating the container's id.

*/

public String id();

/**

* Returns a description of container.

*

* @return A string value indicating the container's description.

*/

public String description();

/**

* Returns the code that represents the destination city for the container.

*

* @return A string value indicating the destination for the container.

*/

public String destinationCity();

}

package shipping;

public interface IDockyard {

/**

* Adds a Container to the dockyard.

*

* This method assumes there is no maximum number of containers that the dockyard can hold.

* The implementation needs to be able to handle any number of containers.

*

* @paramIContainer a container

* @see IContainer

*/

public void addContainer(IContainer container);

/**

* Loads a truck with the next container available based on the truck's destination.

*

* This methods adds the container to the dockyard in an efficient organized way so that containers can be

* loaded onto trucks later in a very efficient manner based on the truck's destination.

*

* @paramITruck A truck used to load a single container.

* @return A boolean value indicating whether or not the truck was loaded.

* @see ITruck

*/

public boolean loadTruck(ITruck truck);

/**

* Counts the number of containers in the overall dockyard.

*

* The implementation needs to be able to return the total number of containers currently stored in the dockyard.

*

* @return The total number of containers in the dockyard.

*/

public int containerCount();

/**

* Counts the number of containers in the overall dockyard.

*

* The implementation needs to be able to return the total number of containers currently stored in the dockyard.

*

* @param String destination city

* @return The total number of containers in the dockyard.

*/

public int containerCount(String destinationCity);

/**

* Prints the details of the current dockyard status.

*

* This method prints the total number of containers and then the number of containers destined for each city.

*

* @return Nothing.

*/

public void printDetails();

}

package shipping;

import java.util.List;

public interface IShip {

/**

* Returns the ship's unique registration id.

*

* @return A string value indicating the ship's registration id.

*/

public String getRegistration();

/**

* Sets the ship's unique registration id.

*

* @param id A string value indicating the ship's registration id.

*/

public void setRegistration(String id);

/**

* Adds a container to the ship.

*

* @return Nothing.

* @see IContainer

*/

public void addContainer(IContainer container);

/**

* Returns a list of the containers that are on the ship.

*

* @return A list of containers currently on the ship.

* @see List

* @see IContainer

*/

public List containers();

/**

* Offloads the containers from the ship and returns the list of containers.

*

* @return A list of containers that are offloaded.

* @see List

* @see IContainer

*/

public List offload();

/**

* Print the details of the ship to the console including the ship

* registration number and the number of containers currently on the ship.

*

* @return Nothing.

*/

public void printDetails();

}

package shipping;

public interface ITruck {

/**

* The truck's registratrion number.

*

* @return A value that represents the truck's registration number.

*/

public String registration();

/**

* Returns the code that represents the destination city for the truck.

*

* @return A string value indicating the destination for the truck.

*/

public String destinationCity();

/**

* Adds a container to the truck.

*

* The implementation should only add the container if there is not already a container on the truck.

* @return True if the container was added and False otherwise.

*/

public boolean addContainer(IContainer container);

/**

* Returns the container from the truck and removes it from the truck.

*

* @return A container reference for the container object being removed from the truck. If there is no container on the truck, the return value is null.

*/

public IContainer offloadContainer();

/**

* Returns a boolean value indicating whether there is a container on the truck.

*

* @return True if the truck has a container and False otherwise.

*/

public boolean hasContainer();

/**

* Prints the truck registration, destination city, and the truck contents.

*

* @return Nothing.

*/

public void printDetails();

}

package shipping;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.List;

import java.util.StringTokenizer;

public abstract class ShippingProcessorBase {

private IDockyard dockyard;

/**

* Class constructor.

*

* @param IDockyard A dockyard object that is used in the processing of events.

* @see IDockyard

*/

public ShippingProcessorBase(IDockyard dockyard) {

this.dockyard = dockyard;

}

/**

* Returns a reference to the dockyard used by the processor.

*

* @return A dockyard reference used by the processor.

* @see IDockyard

*/

protected IDockyard getDockyard() {

return dockyard;

}

/**

* Processes all of the events in the file.

*

* @param String The name of the file to process.

* @return Nothing.

*/

public void processEvents(String fileName) {

this.getDockyard().printDetails();

FileReader fileReader = null;

try {

fileReader = new FileReader(fileName);

} catch (FileNotFoundException e) {

e.printStackTrace();

}

BufferedReader reader = new BufferedReader(fileReader);

String input;

// Read each event and process it

try {

input = reader.readLine();

while (input != null)

{

processShippingEvent(input);

input = reader.readLine();

}

} catch (IOException e) {

e.printStackTrace();

}

// Close the input

try {

fileReader.close();

} catch (IOException e) {

e.printStackTrace();

}

this.getDockyard().printDetails();

};

/**

* This method processes a single shipping event.

*

* The implementation needs to take the String value and process the event.

*

* A "Ship" event represents a ship arriving to the port whereby the containers

* need to be offloaded into the dockyard. You will need to look at the ship manifest

* (based on the Ship's Id) to understand the list of containers on the ship and move

* them to the dockyard by invoking the processShip method.

*

* A "Truck" event reprsents a truck arriving at the dockyard to pickup a container that is destined

* for the same city where the truck is headed. In order to process the truck, the implementation should

* invoke the processTruck method.

*

* @param String The name of the file to process.

* @return Nothing.

*/

protectedvoid processShippingEvent(String input)

{

StringTokenizer st = new StringTokenizer(input, ",");

String eventType = st.nextToken();

if (eventType.equalsIgnoreCase("SHIP")) {

System.out.println("A new ship has arrived. Processing...");

processShip(st.nextToken().trim());

// output the current dockyard status.

System.out.println();

dockyard.printDetails();

} else if (eventType.equalsIgnoreCase("TRUCK")) {

System.out.println("A new truck has arrived. Processing...");

processTruck(st.nextToken().trim(), st.nextToken().trim());

dockyard.printDetails();

}

}

protected abstract List readManifest(String shipId);

/**

* This method processes a single truck event.

*

* The implementation needs to use the registration and destination and process the truck. This involves finding the next

* for the truck's destination and loading it onto the truck from the shipyard.

*

* @param String The truck's registration.

* @param String The truck's destination city.

* @return Nothing.

* @see ITruck

*/

protected abstract void processTruck(String registration, String destination);

/**

* This method processes a single shipping event.

*

* The implementation needs to use the ship passed in to unload containers to the dockyard. Goal is to get all

* of the containers off the ship and add them to the shipyard. The containers need to be added so that the

* containers are queued up for shipping to the destination city when the appropriate truck arrives.

*

* @param String The registration for the arriving ship..

* @return IShip

* @see IShip

*/

protected abstract IShip processShip(String registration);

}

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import shipping.*;

import example1.*;

// Once you have your code implemented in the solution

// package, you need to uncomment the following line

// and comment out the import for example1.* above

//import solution.*;

public class Shipping {

public static void main(String[] args) {

// On any given day, a dockyard will accept incoming containers that arrive on ships. The ships will be unloaded and the containers

// placed into a loading area to be ready for transit. At any point, trucks will enter the dockyard to pick up containers that are

// headed for a particular city. The truck is loaded with the appropriate container and then starts navigating to the destination city.

// This goal of this program is to manage the containers that come into and out of the dockyard.

// A data file containing today's shipping events is provided. You need to complete the program so that the dockyard can store the incoming

// containers and process the containers as trucks arrive to take the containers to a destination city.

// You need to read each row in the ShippingEvents file and process the incoming ships and any trucks that are picking up containers.

// For each ship, you need to load the containers into the dockyard. This means you need a class that implements

String inputFileName = "ShippingEvents.txt";

IDockyard dockyard = new Dockyard();// need to instantiate an object of your class

ShippingProcessor processor = new ShippingProcessor(dockyard);

processor.processEvents("ShippingEvents");

}

}

These are the text files of information that will be used to simulate the dockyard:

S123-Manifest text file:

C123, BOS

C124, NYC

C125, LA

C126, ATL

C127, ATL

C128, NYC

S124-Manifest text file:

C523, BOS

C524, NYC

C525, LA

C526, ATL

C527, ATL

C528, NYC

C529, BOS

C530, BOS

ShippingEvents text file:

Ship, S123

Ship, S124

Truck, T223, BOS

Truck, T224, NYC

Truck, T225, BOS

Truck, T226, BOS

Truck, T227, LA

Truck, T228, BOS

Truck, T229, LA

Truck, T230, BOS

Truck, T231, LA

Here is an example of the output:

I need to make a program that simulates a dockyard. I needto simulate how the dockyard regularly has ships arriving with a lot

\f\f

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!