-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathSlowStarter.java
More file actions
44 lines (35 loc) · 854 Bytes
/
SlowStarter.java
File metadata and controls
44 lines (35 loc) · 854 Bytes
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
package design_patterns.horses;
public class SlowStarter extends Horse{
public double speed;
public double nonReducedSpeed;
public double reducedSpeed;
public double reducedSpeed_2;
public SlowStarter(String n, double s) {
name = n;
nonReducedSpeed = s;
reducedSpeed = s*.90;
reducedSpeed_2 = s*.75;
}
@Override
public void run() {
if (position < 10) {
if (position <= 6) {
speed = reducedSpeed_2;
}else if (position > 6 && position < 9) {
speed = reducedSpeed;
}else {
speed = nonReducedSpeed;
}
position = position + speed*timeIncr;
}else {
finished = true;
}
}
public void display() {
if (!finished) {
System.out.println(name + " has run " + position + " miles.");
}else {
System.out.println(name + " has finished.");
}
}
}