-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPackage.java
More file actions
234 lines (202 loc) · 5.7 KB
/
Copy pathPackage.java
File metadata and controls
234 lines (202 loc) · 5.7 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package components;
import java.awt.Graphics;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
/**
*
* @author Nadav Ishai, ID: 206119893
* abstract class Package
*/
public abstract class Package{
private static int packNum = 1000;
private int packageID;
private Priority priority;
private Status status;
private Address senderAddress;
private Address destinationAddress;
private ArrayList<Tracking> tracking;
private double senderxlocation = 0;
private double senderylocation = 0;
private double destinationylocation = 0;
private static int statusid = 1;
private int customerid;
Package(Priority priority, Address senderAddress, Address destinationAdress, int customerid) {
packageID = packNum;
packNum += 1;
this.priority = priority;
status = Status.CREATION;
this.senderAddress = new Address(senderAddress.Get_Zip(), senderAddress.Get_Street());
this.destinationAddress = new Address(destinationAdress.Get_Zip(), destinationAdress.Get_Street());
tracking = new ArrayList<Tracking>();
tracking.add(new Tracking(MainOffice.GetClock(), null, Status.CREATION));
this.customerid = customerid;
}
public Package(Package p) {
this.packageID = p.GetPackageId();
this.priority = p.GetPriority();
this.status = p.GetRealStatus();
this.senderAddress = p.GetSenderAddress();
this.destinationAddress = p.GetDestinationAddress();
senderxlocation = p.GetSenderXLocation();
senderylocation = p.GetSenderYLocation();
this.destinationylocation = GetDestinationYLocation();
this.tracking = new ArrayList<Tracking>();
for (int i = 0; i < tracking.size(); i++)
this.tracking.set(i, new Tracking(p.tracking.get(i)));
customerid = p.customerid;
}
/**
* abstract class Package toString
*
*/
public String toString() {
return "[packageID="+packageID+", priority="+priority+", status="+status+", startTime=, senderAddress="+senderAddress.Get_Address()+", destinationAddress="+destinationAddress.Get_Address()+", ";
}
/**
* Function equals check the equality between 2 packages statuses
* @param s = other package
* @return true or false
*/
public boolean equals(String s) {
if(this.GetStatus().compareTo(s) == 0)
return true;
return false;
}
/**
* Function equals check the equality between 2 packages by the ID
* @param s = other package
* @return true or false
*/
public boolean equals(Package s) {
if(this.GetPackageId() == s.packageID)
return true;
return false;
}
/**
* Function addTracking add tracking to a package
* @param node = location of the package
* @param status = status of the package
*/
void addTracking(Node node, Status status) {
Tracking t = new Tracking(MainOffice.GetClock(), node, status);
tracking.add(t);
}
/**
* Function GetTrackingList return package tracking list
* @return tracking
*/
public ArrayList<Tracking> GetTrackingList() {
return tracking;
}
/**
* Function GetStatus return package status as String
* @return
*/
public String GetStatus() {
return status.GetStatus();
}
/**
* Function PrintTracking prints all the tracking of a package
*/
public void PrintTracking() {
for (int i = 0; i < tracking.size(); i++)
System.out.print(tracking.get(i));
}
/**
* Function ChangeStatus changes package status
* @param s = change to s status
*/
public void ChangeStatus(Status s) {
status = s;
String str;
str = statusid + ". " + "Package number: " + packageID + ", status = " + s + ", Customer = " + customerid + "\n";
statusid += 1;
components.MainOffice.Write(str);
}
/**
* Function GetPackageId return package id
* @return packageId
*/
public int GetPackageId() {
return packageID;
}
/**
* Function GetSenderAddress return sender address
* @return senderAddress
*/
public Address GetSenderAddress() {
return senderAddress;
}
/**
* Function GetDestinationAddress return destination address
* @return destinationAddress
*/
public Address GetDestinationAddress() {
return destinationAddress;
}
/**
* Function GetPriority return package priority
* @return priority
*/
public Priority GetPriority() {
return priority;
}
public abstract String GetPackageType();
/**
* Function SetSenderLocation sets the x & y coordinates of a sender
* @param x the x position of the sender
* @param y the y position of the sender
*/
public void SetSenderLocation(double x, double y) {
senderxlocation = x;
senderylocation = y;
}
/**
* Function GetSenderXLocation return the x position of sender
* @return int senderxlocation
*/
public double GetSenderXLocation() {
return senderxlocation;
}
/**
* Function GetSenderYLocation returns the sender y position
* @return int senderylocation
*/
public double GetSenderYLocation() {
return senderylocation;
}
/**
* Function SetDestinationYLocation sets the destination y position
* @param y the y position of the destination
*/
public void SetDestinationYLocation(double y) {
destinationylocation = y;
}
/**
* Function GetDestinationYLocation return the destination y position
* @return int destinationylocation
*/
public double GetDestinationYLocation() {
return destinationylocation;
}
/**
* function to decrease id
* @param num
*/
public static void DecreaseId(int num) {
packNum -= num;
}
/**
* function to return status;
*/
public Status GetRealStatus() {
return status;
}
/**
* function to set id
* @param id
*/
public void SetCustomerId(int id) {
customerid = id;
}
}