Class Plant

java.lang.Object
extended by Plant

public class Plant
extends java.lang.Object

This class simulates a Plastics Injection molding plant that has a single large hopper for pellets and can have any number of molding machines and any number of storage areas. We only make plastic containers that require exactly 500 gms of pellets. Each machine can have a different production rate and each storage area can hold a different amount of containers. When containers are shipped they are removed from storage areas always starting from the first storage area (index 0).


Constructor Summary
Plant()
          Creates a new instance of Plant
Plant(java.lang.String id, double hopperSize)
          Constructor for Plant that initializes key variables.
 
Method Summary
 void addMachine(java.lang.String id, int productionRate)
          Add a machine to the list of machines.
 void addPellets(double kg)
          Add a specified amount of plastic pellets to the Hopper.
 void addStorageArea(int capacity)
          Add a storage area to the list of storage areas.
 int getAvailableStorage()
          Gets the total room available in all storage areas by iterating through all storage areas and adding the available room in each.
 int getAvailableStorage(int location)
          Gets the room available in a specific storage area.
 double getHopperSize()
          Returns hopper size (kg).
 java.lang.String getName()
          Returns plant name.
 double getPellets()
          Returns the amount of pellets in the hopper (kg).
 int getProductionCapacity()
          Returns production capacity of the entire plant.
 int getStock()
          Gets the total amount of parts in all storage areas by iterating through all storage areas and adding the stock in each.
 int getStock(int location)
          Gets the stock that is to be found in a specific storage area specified by its index.
 void run(int minutes)
          Run the plant for a specified number of minutes or until a NotEnoughPelletsException or NoMoreStorageException occurs whichever comes first.
 int runStatus()
          Returns the total number of minutes the plant ran during the last call to the run() method.
 void setHopperSize(double hopperSize)
          Sets the hopper size (in Kg).
 void setName(java.lang.String name)
          Sets plant name.
 void setPellets(double kg)
          Set the amount of pellets in the Hopper to the value of the parameter.
 void shipParts(int count)
          Method will attempt to ship parts from the storage areas.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Plant

public Plant()
Creates a new instance of Plant


Plant

public Plant(java.lang.String id,
double hopperSize)
Constructor for Plant that initializes key variables.

Parameters:
id - Name of plant.
hopperSize - Size of hopper in kg.
Method Detail

getName

public java.lang.String getName()
Returns plant name.

Returns:
Plant name.

setName

public void setName(java.lang.String name)
Sets plant name.

Parameters:
name - Name of plant.

getHopperSize

public double getHopperSize()
Returns hopper size (kg).

Returns:
Hopper size in kg.

setHopperSize

public void setHopperSize(double hopperSize)
Sets the hopper size (in Kg).

Parameters:
hopperSize - Hopper size in kg.

getPellets

public double getPellets()
Returns the amount of pellets in the hopper (kg).

Returns:
Amount of pellets in the hopper in kg.

setPellets

public void setPellets(double kg)
throws HopperFullException
Set the amount of pellets in the Hopper to the value of the parameter. If the amount is greater than the hopper capacity DONOT set the internal attribute and throw a HopperFullException

Parameters:
kg - Amount of pellets (in kg).
Throws:
HopperFullException - Thrown when adding or setting Hopper size exceeds Hopper capacity.

addPellets

public void addPellets(double kg)
throws HopperFullException
Add a specified amount of plastic pellets to the Hopper. If the amount to be added will cause an overflow DONOT add the amount to the current amount of pellets and throw a HopperFullException

Parameters:
kg - Amount of pellets to add (in kg).
Throws:
HopperFullException - Thrown when adding pellets will exceed hopper capacity.

addStorageArea

public void addStorageArea(int capacity)
Add a storage area to the list of storage areas.

Parameters:
capacity - Capacity of the new storage area.

addMachine

public void addMachine(java.lang.String id,
int productionRate)
Add a machine to the list of machines.

Parameters:
id - Id of the new machine as a String.
productionRate - Production rate in parts per minute.

getProductionCapacity

public int getProductionCapacity()
Returns production capacity of the entire plant.

Returns:
Production capacity of plant. Sum of production capacity of each machine in the plant.

getAvailableStorage

public int getAvailableStorage()
Gets the total room available in all storage areas by iterating through all storage areas and adding the available room in each.

Returns:
Total available room in all storage areas.

getAvailableStorage

public int getAvailableStorage(int location)
throws StorageLocationException
Gets the room available in a specific storage area. If the capacity of storage area 0 is 200 and the count of stock in area 0 is 40 then the available storage is 160.

Parameters:
location - Index of a storage area.
Returns:
Available storage at storage index.
Throws:
StorageLocationException - On index out of range.

getStock

public int getStock()
Gets the total amount of parts in all storage areas by iterating through all storage areas and adding the stock in each.

Returns:
Total stock in all storage areas.

getStock

public int getStock(int location)
throws StorageLocationException
Gets the stock that is to be found in a specific storage area specified by its index.

Parameters:
location - Index of storage area.
Returns:
Stock of parts in a specified storage area.
Throws:
StorageLocationException - if the location is not within range

shipParts

public void shipParts(int count)
throws NotEnoughPartsException
Method will attempt to ship parts from the storage areas. It will accomplish this by decrementing each storage area starting from index 0 until the total amount decremented is equal to count.
Example a: StorageArea 0 has 100 units and StorageArea 1 has 50 If a request is made to ship 120 parts then StorageArea 0 is decremented to 0 (emptied) and Area 1 is decremented by 20.
Example b: StorageArea 0 has 200 units and StorageArea 1 has 50 If a request is made to ship 120 parts then StorageArea 0 is decremented by 120 to leave 80. Area 1 is not changed.
Example c: StorageArea 0 has 60 units and StorageArea 1 has 50 If a request is made to ship 120 parts then no changes are made to either Area 0 or 1 but a NotEnoughPartsException is thrown.

Parameters:
count - Number of parts to be shipped.
Throws:
NotEnoughPartsException - When there are insufficient parts to ship.

run

public void run(int minutes)
throws NoMoreStorageException,
NotEnoughPelletsException
Run the plant for a specified number of minutes or until a NotEnoughPelletsException or NoMoreStorageException occurs whichever comes first. Please note that you will throw these exceptions and it is possible that the method might have to catch and rethrow one or both of the specified exceptions. This method must appropriately update a status variable which can be retrieved using runStatus() with the total length of the run. This would typically be exactly the same as the minutes parameter but might be less if there was an exception. Set this private variable before returning and before throwing an exception. If two consecutive calls are made to the run() routine, the second run of the plant should continue from where the previous run left off. If the previous run ran for 60 minutes starting with 4000 kg. of pellets and consumed 1000 kg. of pellets, the second run should start with 3000 kg. of pellets. .

Parameters:
minutes - No of minutes to run the plant.
Throws:
NoMoreStorageException
NotEnoughPelletsException

runStatus

public int runStatus()
Returns the total number of minutes the plant ran during the last call to the run() method. This would typically be exactly the same as the minutes parameter in the run() method but might be less if there was an exception.

Returns:
The no. minutes of the last run of plant.