-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobot.java
More file actions
36 lines (34 loc) · 996 Bytes
/
Copy pathRobot.java
File metadata and controls
36 lines (34 loc) · 996 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
public class Robot implements Moving{
private final int maxRun = 5000;
private final int maxJump = 10;
@Override
public void run(int length) {
System.out.println("Robot runs " + length);
}
@Override
public void jump(int height) {
System.out.println("Robot jumps " + height);
}
@Override
public boolean passTheBarrier(Barrier barrier) {
if (barrier instanceof Wall) {
int barrierHeight = ((Wall) barrier).getHeight();
if (barrierHeight <= maxJump) {
jump(barrierHeight);
return true;
}
else
return false;
}
if (barrier instanceof Treadmill) {
int barrierLength = ((Treadmill) barrier).getLength();
if (barrierLength <= maxRun) {
run(barrierLength);
return true;
}
else
return false;
}
return false;
}
}