-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocation.java
191 lines (158 loc) · 4.53 KB
/
Location.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
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
//DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE
package locations;
import java.util.ArrayList;
import passengers.*;
/**
* This class implements a simple location with ID and x and y coordinates. The
* location can save incoming and outgoing passengers with using history and
* current lists.
*
* @author Hasan Baki Kucukcakiroglu
* @since 2020-03-28
*
*/
public class Location {
/**
* @param ID location's ID
* @param locationX x coordinate of the location
* @param locationY y coordinate of the location
* @param history the array list which keeps all passenger that been this
* location in the past or now
* @param current the array list which keeps all passengers who currently been
* here.
*/
private int ID;
private double locationX;
private double locationY;
private ArrayList<Passenger> history = new ArrayList<>();
private ArrayList<Passenger> current = new ArrayList<>();
/**
* This constructs a location by using ID, X coordinate and Y coordinate.
*
* @param ID the ID of location.
* @param locationX the X coordinate of the location.
* @param locationY the Y coordinate of the location.
*/
public Location(int ID, double locationX, double locationY) {
this.ID = ID;
this.locationX = locationX;
this.locationY = locationY;
}
/**
* This method calculates and returns the distance between this location and
* given other location using basic math.
*
* @param other the another location that we calculate distance with this
* location.
* @return the distance between this location and given other location.
*/
public double getDistance(Location other) {
return Math.sqrt(Math.pow(this.locationX - other.locationX, 2) + Math.pow(this.locationY - other.locationY, 2));
}
/**
* This method saves all passengers who has visited this location. This keep
* them in both of history and current locations.
*
* @param p the passenger who has visited this location.
*/
public void incomingPassenger(Passenger p) {
if (!history.contains(p)) {
this.history.add(p);
}
this.current.add(p);
}
/**
* This method saves all passengers who has left this location. This delete them
* from current list.
*
* @param p the passenger who has left this location.
*/
public void outgoingPassenger(Passenger p) {
this.current.remove(p);
}
/**
* This method returns the ID of the location.
*
* @return the ID of the location.
*/
public int getID() {
return ID;
}
/**
* This method enables us to set location's ID as given ID.
*
* @param iD the ID that will be given to location.
*/
public void setID(int iD) {
ID = iD;
}
/**
* This method returns the X coordinate of this location.
*
* @return X coordinate of this location.
*/
public double getLocationX() {
return locationX;
}
/**
* This method enables us to set location's X coordinate as given X coordinate .
*
* @param locationX the X coordinate that will be given to location.
*/
public void setLocationX(double locationX) {
this.locationX = locationX;
}
/**
* This method returns the Y coordinate of this location.
*
* @return Y coordinate of this location.
*/
public double getLocationY() {
return locationY;
}
/**
* This method enables us to set location's Y coordinate as given Y coordinate.
*
* @param locationY Y coordinate that will be given to location.
*/
public void setLocationY(double locationY) {
this.locationY = locationY;
}
/**
* This method returns current array list of this location. Current array list
* keeps all passengers who is in this location right now.
*
* @return current array list of this location.
*/
public ArrayList<Passenger> getCurrent() {
return current;
}
/**
* This method enables us to set location's current array list as given array
* list.
*
* @param current the array list that will be given to location.
*/
public void setCurrent(ArrayList<Passenger> current) {
this.current = current;
}
/**
* This method returns history array list of this location. History array list
* keeps all passengers that been in this location.
*
* @return history array list of this location.
*/
public ArrayList<Passenger> getHistory() {
return history;
}
/**
* This method enables us to set location's history array list as given array
* list.
*
* @param history the array list that will be given to location.
*/
public void setHistory(ArrayList<Passenger> history) {
this.history = history;
}
}
//DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE