-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCity.java
More file actions
77 lines (61 loc) · 1.4 KB
/
City.java
File metadata and controls
77 lines (61 loc) · 1.4 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
package stormPath;
import java.awt.geom.RectangularShape;
import java.util.ArrayList;
import javax.xml.transform.sax.SAXTransformerFactory;
public class City {
private String name;
private ArrayList<Storm> storms;
public City(String name) {
this.name = name;
this.storms = new ArrayList<Storm>();
}
public String getName() {
// TODO Auto-generated method stub
return this.name;
}
public boolean wasHit(Storm s) {
// TODO Auto-generated method stub
return this.storms.contains(s);
}
public void addStorm(Storm s) {
if (!this.storms.contains(s)){
this.storms.add(s);
}
if (!s.getCities().contains(this)){
s.addCity(this);
}
}
public boolean onSamePath(City c2) {
for (Storm s:this.storms){
if (c2.wasHit(s)){
return true;
}
}
return false;
}
@Override
public String toString(){
String result = this.getName() + " (";
if (this.storms.size() != 0){
for (Storm s : this.storms){
result += s.getName() + ", ";
}
}else{
return result += ")";
}
return result.substring(0, result.length() - 2) + ")";
}
public boolean equals(City otherCity){
boolean sameName = this.getName().equals(otherCity.getName());
boolean sameSize = this.storms.size() == otherCity.storms.size();
if (!(sameName && sameSize)){
return false;
}
for (Storm s:this.storms){
if (!otherCity.wasHit(s)){
return false;
}
}
return true;
}
}