-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTown.java
More file actions
54 lines (44 loc) · 1.03 KB
/
Town.java
File metadata and controls
54 lines (44 loc) · 1.03 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
import java.util.ArrayList;
/*
* Class for each seperate town
*/
public class Town {
private String town;
private ArrayList<Edge> connectedTo;
private int unloadingCost;
public Town(String town, int unloadingCost) {
this.town = town;
this.unloadingCost = unloadingCost;
this.connectedTo = new ArrayList<>();
}
public void addEdge(Edge e) {
connectedTo.add(e);
}
public String getTown() {
return this.town;
}
public int getUnloadingCost() {
return this.unloadingCost;
}
public void addEdgeTo(Town to, int cost) {
connectedTo.add(new Edge(this, to, cost));
}
//checks if curr town is connected to another town
public boolean hasEdge(Town to) {
for(Edge e : connectedTo) {
if (e.getConnectedTown(to).equals(to)) {
return true;
}
}
return false;
}
public ArrayList<Edge> getEdgeConnections() {
return connectedTo;
}
public boolean equalsName(String townInput) {
if(townInput.equals(town)) {
return true;
}
return false;
}
}