-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoadEntry.java
98 lines (66 loc) · 1.52 KB
/
RoadEntry.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
package assignment1;
import java.util.ArrayList;
public class RoadEntry {
public String roadName;
public String startJunc;
public String endJunc;
public int roadLength;
public int nLots;
public RoadEntry(String roadName,String junction1,String junction2,int roadLength, int nLots){
this.roadName = roadName;
this.startJunc = junction1;
this.endJunc = junction2;
this.roadLength = roadLength;
this.nLots = nLots;
}
public String getRoadName() {
return roadName;
}
public String getStartJunc() {
return startJunc;
}
public void setStartJunc(String startJunc) {
this.startJunc = startJunc;
}
public String getEndJunc() {
return endJunc;
}
public void setEndJunc(String endJunc) {
this.endJunc = endJunc;
}
public int getRoadLength() {
return roadLength;
}
public int getnLots() {
return nLots;
}
public double getCostBetweenEachLot(){
return roadLength/(nLots/2.0);
}
public double distanceBetweenTwoNodes(int lotNum1, int lotNum2)
{
if(lotNum1%2==0)
lotNum1=lotNum1-1;
if(lotNum2%2==0)
lotNum2=lotNum2-1;
if(lotNum1==lotNum2)
return 0;
else
return (Math.abs(lotNum1-lotNum2)/2*getCostBetweenEachLot());
}
public double distanceToStartJunc(double lotNum){
if(lotNum<=nLots)
{
if((lotNum%2)==0)
lotNum = lotNum-1;
return (lotNum/2)*getCostBetweenEachLot();
}
else
return -1;
}
public double distanceToEndJunc(double lotNum){
if(lotNum<=nLots)
return (roadLength-(distanceToStartJunc(lotNum)));
return -1;
}
}