computer science
PROJ_METCS520_2/.classpath
PROJ_METCS520_2/.project
PROJ_METCS520_2 org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature
PROJ_METCS520_2/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.8
PROJ_METCS520_2/S123-Manifest
C123, BOS C124, NYC C125, LA C126, ATL C127, ATL C128, NYC
PROJ_METCS520_2/S124-Manifest
C523, BOS C524, NYC C525, LA C526, ATL C527, ATL C528, NYC C529, BOS C530, BOS
PROJ_METCS520_2/ShippingEvents
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
PROJ_METCS520_2/bin/Shipping.class
public synchronized class Shipping { public void Shipping(); public static void main(String[]); }
PROJ_METCS520_2/bin/example1/Container.class
package example1; public synchronized class Container implements shipping.IContainer { public void Container(); public String id(); public String description(); public String destinationCity(); }
PROJ_METCS520_2/bin/example1/Dockyard.class
package example1; public synchronized class Dockyard implements shipping.IDockyard { public void Dockyard(); public void addContainer(shipping.IContainer); public boolean loadTruck(shipping.ITruck); public int containerCount(); public int containerCount(String); public void printDetails(); }
PROJ_METCS520_2/bin/example1/Ship.class
package example1; public synchronized class Ship implements shipping.IShip { public void Ship(); public java.util.List containers(); public java.util.List offload(); public String getRegistration(); public void setRegistration(String); public void addContainer(shipping.IContainer); public void printDetails(); }
PROJ_METCS520_2/bin/example1/ShippingProcessor.class
package example1; public synchronized class ShippingProcessor extends shipping.ShippingProcessorBase { public void ShippingProcessor(shipping.IDockyard); protected void processShippingEvent(String); protected void processTruck(String, String); protected shipping.IShip processShip(String); protected java.util.List readManifest(String); }
PROJ_METCS520_2/bin/example1/Truck.class
package example1; public synchronized class Truck implements shipping.ITruck { public void Truck(); public String registration(); public String destinationCity(); public boolean addContainer(shipping.IContainer); public shipping.IContainer offloadContainer(); public boolean hasContainer(); public void printDetails(); }
PROJ_METCS520_2/bin/shipping/IContainer.class
package shipping; public abstract interface IContainer { public abstract String id(); public abstract String description(); public abstract String destinationCity(); }
PROJ_METCS520_2/bin/shipping/IDockyard.class
package shipping; public abstract interface IDockyard { public abstract void addContainer(IContainer); public abstract boolean loadTruck(ITruck); public abstract int containerCount(); public abstract int containerCount(String); public abstract void printDetails(); }
PROJ_METCS520_2/bin/shipping/IShip.class
package shipping; public abstract interface IShip { public abstract String getRegistration(); public abstract void setRegistration(String); public abstract void addContainer(IContainer); public abstract java.util.List containers(); public abstract java.util.List offload(); public abstract void printDetails(); }
PROJ_METCS520_2/bin/shipping/ITruck.class
package shipping; public abstract interface ITruck { public abstract String registration(); public abstract String destinationCity(); public abstract boolean addContainer(IContainer); public abstract IContainer offloadContainer(); public abstract boolean hasContainer(); public abstract void printDetails(); }
PROJ_METCS520_2/bin/shipping/ShippingProcessorBase.class
package shipping; public abstract synchronized class ShippingProcessorBase { private IDockyard dockyard; public void ShippingProcessorBase(IDockyard); protected IDockyard getDockyard(); public void processEvents(String); protected void processShippingEvent(String); protected abstract java.util.List readManifest(String); protected abstract void processTruck(String, String); protected abstract IShip processShip(String); }
PROJ_METCS520_2/src/Shipping.java
PROJ_METCS520_2/src/Shipping.java
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 to create 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"
);
}
}
PROJ_METCS520_2/src/example1/Container.java
PROJ_METCS520_2/src/example1/Container.java
package
example1
;
import
shipping
.
IContainer
;
public
class
Container
implements
IContainer
{
@
Override
public
String
id
()
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
public
String
description
()
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
public
String
destinationCity
()
{
// TODO Auto-generated method stub
return
null
;
}
}
PROJ_METCS520_2/src/example1/Dockyard.java
PROJ_METCS520_2/src/example1/Dockyard.java
package
example1
;
import
shipping
.
IContainer
;
import
shipping
.
IDockyard
;
import
shipping
.
ITruck
;
public
class
Dockyard
implements
IDockyard
{
@
Override
public
void
addContainer
(
IContainer
container
)
{
// TODO Auto-generated method stub
}
@
Override
public
boolean
loadTruck
(
ITruck
truck
)
{
// TODO Auto-generated method stub
return
false
;
}
@
Override
public
int
containerCount
()
{
// TODO Auto-generated method stub
return
0
;
}
@
Override
public
int
containerCount
(
String
destinationCity
)
{
// TODO Auto-generated method stub
return
0
;
}
@
Override
public
void
printDetails
()
{
// TODO Auto-generated method stub
}
}
PROJ_METCS520_2/src/example1/Ship.java
PROJ_METCS520_2/src/example1/Ship.java
package
example1
;
import
java
.
util
.
List
;
import
shipping
.
IContainer
;
import
shipping
.
IShip
;
public
class
Ship
implements
IShip
{
@
Override
public
List
<
IContainer
>
containers
()
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
public
List
<
IContainer
>
offload
()
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
public
String
getRegistration
()
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
public
void
setRegistration
(
String
id
)
{
// TODO Auto-generated method stub
}
@
Override
public
void
addContainer
(
IContainer
container
)
{
// TODO Auto-generated method stub
}
@
Override
public
void
printDetails
()
{
// TODO Auto-generated method stub
}
}
PROJ_METCS520_2/src/example1/ShippingProcessor.java
PROJ_METCS520_2/src/example1/ShippingProcessor.java
package
example1
;
import
java
.
util
.
List
;
import
shipping
.
IContainer
;
import
shipping
.
IDockyard
;
import
shipping
.
IShip
;
import
shipping
.
ITruck
;
import
shipping
.
ShippingProcessorBase
;
public
class
ShippingProcessor
extends
ShippingProcessorBase
{
public
ShippingProcessor
(
IDockyard
dockyard
)
{
super
(
dockyard
);
// TODO Auto-generated constructor stub
}
@
Override
protected
void
processShippingEvent
(
String
input
)
{
// TODO Auto-generated method stub
}
@
Override
protected
void
processTruck
(
String
registration
,
String
destination
)
{
// TODO Auto-generated method stub
}
@
Override
protected
IShip
processShip
(
String
registration
)
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
protected
List
<
IContainer
>
readManifest
(
String
shipId
)
{
// TODO Auto-generated method stub
return
null
;
}
}
PROJ_METCS520_2/src/example1/Truck.java
PROJ_METCS520_2/src/example1/Truck.java
package
example1
;
import
shipping
.
IContainer
;
import
shipping
.
ITruck
;
public
class
Truck
implements
ITruck
{
@
Override
public
String
registration
()
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
public
String
destinationCity
()
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
public
boolean
addContainer
(
IContainer
container
)
{
// TODO Auto-generated method stub
return
false
;
}
@
Override
public
IContainer
offloadContainer
()
{
// TODO Auto-generated method stub
return
null
;
}
@
Override
public
boolean
hasContainer
()
{
// TODO Auto-generated method stub
return
false
;
}
@
Override
public
void
printDetails
()
{
// TODO Auto-generated method stub
}
}
PROJ_METCS520_2/src/shipping/IContainer.java
PROJ_METCS520_2/src/shipping/IContainer.java
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.
* <p>
*
@return
A string value indicating the container's description.
*/
public
String
description
();
/**
* Returns the code that represents the destination city for the container.
* <p>
*
@return
A string value indicating the destination for the container.
*/
public
String
destinationCity
();
}
PROJ_METCS520_2/src/shipping/IDockyard.java
PROJ_METCS520_2/src/shipping/IDockyard.java
package
shipping
;
public
interface
IDockyard
{
/**
* Adds a Container to the dockyard.
* <p>
* 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.
*
*
@param
IContainer a container
*
@see
IContainer
*/
public
void
addContainer
(
IContainer
container
);
/**
* Loads a truck with the next container available based on the truck's destination.
* <p>
* 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.
*
*
@param
ITruck 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* This method prints the total number of containers and then the number of containers destined for each city.
*
*
@return
Nothing.
*/
public
void
printDetails
();
}
PROJ_METCS520_2/src/shipping/IShip.java
PROJ_METCS520_2/src/shipping/IShip.java
package
shipping
;
import
java
.
util
.
List
;
public
interface
IShip
{
/**
* Returns the ship's unique registration id.
* <p>
*
@return
A string value indicating the ship's registration id.
*/
public
String
getRegistration
();
/**
* Sets the ship's unique registration id.
* <p>
*
@param
id A string value indicating the ship's registration id.
*/
public
void
setRegistration
(
String
id
);
/**
* Adds a container to the ship.
* <p>
*
@return
Nothing.
*
@see
IContainer
*/
public
void
addContainer
(
IContainer
container
);
/**
* Returns a list of the containers that are on the ship.
* <p>
*
@return
A list of containers currently on the ship.
*
@see
List
*
@see
IContainer
*/
public
List
<
IContainer
>
containers
();
/**
* Offloads the containers from the ship and returns the list of containers.
* <p>
*
@return
A list of containers that are offloaded.
*
@see
List
*
@see
IContainer
*/
public
List
<
IContainer
>
offload
();
/**
* Print the details of the ship to the console including the ship
* registration number and the number of containers currently on the ship.
* <p>
*
@return
Nothing.
*/
public
void
printDetails
();
}
PROJ_METCS520_2/src/shipping/ITruck.java
PROJ_METCS520_2/src/shipping/ITruck.java
package
shipping
;
public
interface
ITruck
{
/**
* The truck's registratrion number.
* <p>
*
@return
A value that represents the truck's registration number.
*/
public
String
registration
();
/**
* Returns the code that represents the destination city for the truck.
* <p>
*
@return
A string value indicating the destination for the truck.
*/
public
String
destinationCity
();
/**
* Adds a container to the truck.
* <p>
* 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.
* <p>
*
@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.
* <p>
*
@return
True if the truck has a container and False otherwise.
*/
public
boolean
hasContainer
();
/**
* Prints the truck registration, destination city, and the truck contents.
* <p>
*
@return
Nothing.
*/
public
void
printDetails
();
}
PROJ_METCS520_2/src/shipping/ShippingProcessorBase.java
PROJ_METCS520_2/src/shipping/ShippingProcessorBase.java
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.
* <p>
*
@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.
* <p>
*
@return
A dockyard reference used by the processor.
*
@see
IDockyard
*/
protected
IDockyard
getDockyard
()
{
return
dockyard
;
}
/**
* Processes all of the events in the file.
* <p>
*
@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.
* <p>
* 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.
*/
protected
void
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
<
IContainer
>
readManifest
(
String
shipId
);
/**
* This method processes a single truck event.
* <p>
* 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.
* <p>
* 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
);
}