-
Notifications
You must be signed in to change notification settings - Fork 1
/
Street.java
57 lines (47 loc) · 1.25 KB
/
Street.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
/**
* A representation for streets using the following characteristics: beginning
* and ending points, street name, and the street ID.
*
*/
public class Street {
private Point firstPoint, secondPoint;
private String name;
private int id;
public Street(int id, Point firstPoint, Point secondPoint, String name) {
this.id = id;
this.firstPoint = firstPoint;
this.secondPoint = secondPoint;
this.name = name;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setPoints(Point firstPoint, Point secondPoint) {
this.firstPoint = firstPoint;
this.secondPoint = secondPoint;
}
public Point getFirstPoint() {
return firstPoint;
}
public Point getSecondPoint() {
return secondPoint;
}
/**
* Returns the distance of this street using the distance formula with the
* street's beginning and ending locations.
*/
public Double getDistance() {
double x = Math.pow(secondPoint.getX() - firstPoint.getX(), 2)
+ Math.pow(secondPoint.getY() - firstPoint.getY(), 2);
return Math.sqrt(x);
}
}