-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWarehouse.java
76 lines (69 loc) · 1.94 KB
/
Warehouse.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.Stack;
/**
* A warehouse has a stack of trucks
*
* @author Emmett O'Toole
* @version 4-23-17
*/
public class Warehouse extends Facility
{
//A stack of trucks
private Stack<Truck>trucks;
/**
* Constructor for objects of class Warehouse
* @param int id the unique id of the warehouse
* @param Location a the location of the warehouse
* @param int the number of trucks
*/
public Warehouse(int id,Location a,int numberOfTrucks)
{
super(id, 'W');
this.facilityLoc=a;
//Initializes the stack of trucks
this.trucks=new Stack<Truck>();
//Adds empty trucks to the stack
for(int i=0;i<numberOfTrucks;i++){
trucks.push(new Truck(this));
}
}
/**
* Distance from method
* Uses the distance method from location to calculate
* The distance between a warehouse and a given location
* @param Location x the location from which the distance of the warehouse is being measured
* @return int the distance
*/
public int distanceFrom(Facility x)
{
return facilityLoc.distance(x.getLocation());
}
/**
* Get id method
* @return int the unique id of the warehouse
*/
public int getID(){
return this.ID;
}
/**
* Get location method
* @return Location the location of the warehouse
*/
public Location getLocation(){
return this.facilityLoc;
}
/**
* Get next truck method returns a truck from the top of the stack
* @return Truck the truck from the top of the stack
*/
public Truck getNextTruck(){
//Pops the truck and returns it
return trucks.pop();
}
public String toString()
{
return "W" + ID;
}
public boolean trucksLeft(){
return !this.trucks.isEmpty();
}
}