forked from WildCodeSchool/quest-java-oop3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEagle.java
More file actions
74 lines (58 loc) · 1.74 KB
/
Eagle.java
File metadata and controls
74 lines (58 loc) · 1.74 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
public class Eagle extends Bird implements Fly{
private boolean flying;
private int altitude;
public Eagle(String name) {
super(name);
this.flying = false;
this.altitude = 0;
}
public int getAltitude() {
return altitude;
}
public boolean isFlying() {
return flying;
}
@Override
public String sing() {
return "Screech!";
}
@Override
public void takeOff() {
if (!this.flying && this.altitude == 0) {
this.flying = true;
System.out.printf("%s takes off in the sky.%n", this.getName());
}
}
@Override
public int descend(int meters) {
if (this.flying) {
this.altitude = Math.min(this.altitude - meters, 325);
System.out.printf("%s flies downward, altitude : %d%n", this.getName(), this.altitude);
}
return this.altitude;
}
@Override
public int ascend(int meters) {
if (this.flying) {
this.altitude = Math.max(this.altitude + meters, 0);
System.out.printf("%s flies upward, altitude : %d%n", this.getName(), this.altitude);
}
return this.altitude;
}
@Override
public void land() {
if (this.altitude <= 10) {
System.out.printf("%s lands on the ground.%n", this.getName());
} else {
System.out.printf("%s is too high, it can't land.%n", this.getName());
}
}
@Override
public void glide() {
if (this.flying && this.altitude == 0) {
System.out.printf("%s is walking on the ground.%n", this.getName());
} else {
System.out.printf("%s glides into the air.%n", this.getName());
}
}
}