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
72 lines (59 loc) · 1.81 KB
/
Copy pathEagle.java
File metadata and controls
72 lines (59 loc) · 1.81 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
71
72
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 (!flying) {
this.flying = true;
System.out.printf (this.getName()+" takes off in the sky.%n");
}
else {System.out.println (this.getName()+" is already in the air.");}
}
@Override
public int ascend (int meters) {
this.altitude = this.altitude + meters;
System.out.printf (this.getName()+" flies upward. Altitude: "+this.altitude+".%n");
return this.altitude;
}
@Override
public int descend (int meters) {
if (this.flying) {this.altitude = Math.max(this.altitude - meters, 0);
System.out.println (this.getName()+" flies downward. Altitude: "+this.altitude+".");
}
else {System.out.println (this.getName()+" can't get down any further. He's already grounded.");}
if (this.altitude==0&&this.flying){
this.flying = false;
}
return this.altitude;
}
@ Override
public void land () {
if (this.flying) {
this.altitude = 0;
this.flying = false;
System.out.println (this.getName()+" lands on the ground.");}
else {System.out.println (this.getName()+" is already stationary.");}
}
@ Override
public void glides (){
if (this.flying) {
System.out.println (this.getName()+" is gliding through the air.");
}
else {System.out.println (this.getName()+" can't glide, they're grounded.");}
}
}