|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectTrainHub
public class TrainHub
This class represents a train hub and provides the common operations needed for managing the incoming and outgoing trains. It has a LinkedList of Train as a member variable and manages it. COMPLETE THIS CLASS AND HAND IN THIS FILE
LinkedList
,
Train
,
Config
Field Summary | |
---|---|
private LinkedList<Train> |
trains
The internal data structure of a hub is a linked list of Trains |
Constructor Summary | |
---|---|
TrainHub()
Constructs and initializes TrainHub object |
Method Summary | |
---|---|
boolean |
departAllTrains()
This method deletes all the trains. |
boolean |
departTrain(java.lang.String dest)
This method is used to depart the train to the given destination. |
boolean |
displayAllTrains()
This method is used to display all the departing trains in the train hub. |
boolean |
displayTrain(java.lang.String dest)
Display the specific train for a destination. |
Train |
findTrain(java.lang.String dest)
This method tries to find the train in the list of trains, departing to the given destination city. |
int |
getWeight(java.lang.String name)
This method iterates through all the trains in the list and finds the sum of weights of given cargo in all trains. |
void |
processIncomingTrain(Train train)
This method processes the incoming train. |
CargoCar |
removeCargo(java.lang.String dest,
java.lang.String name)
This method removes the first cargo car going to the given destination city and carrying the given cargo. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private LinkedList<Train> trains
Constructor Detail |
---|
public TrainHub()
Method Detail |
---|
public void processIncomingTrain(Train train)
train
- Incoming train (list or cargo cars)public Train findTrain(java.lang.String dest)
dest
- Destination city for which train has to be found.
public CargoCar removeCargo(java.lang.String dest, java.lang.String name)
dest
- Destination cityname
- Cargo name
public int getWeight(java.lang.String name)
name
- Name of the cargo
public boolean departTrain(java.lang.String dest)
dest
- Destination city for which corresponding train has to be departed/deleted.
public boolean departAllTrains()
public boolean displayTrain(java.lang.String dest)
dest
- Destination city for the train the to be displayed.
public boolean displayAllTrains()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |