diff --git a/Eagle.java b/Eagle.java index d0e8799..291d9fa 100644 --- a/Eagle.java +++ b/Eagle.java @@ -1,4 +1,4 @@ -public class Eagle extends Bird { +public class Eagle extends Bird implements Fly { private boolean flying; private int altitude; @@ -21,4 +21,39 @@ public boolean isFlying() { public String sing() { return "Screech!"; } + + public void takeOff(){ + if(!this.flying && altitude==0){ + this.flying = true; + System.out.println(this.getName()+" takes off in the sky."); + } + } + public int ascend(int meters){ + if(this.flying){ + this.altitude = this.altitude + meters; + System.out.println(this.getName()+" flies upward, altitude: "+ this.altitude); + } + return this.altitude; + } + public void glide(){ + if(this.flying) { + System.out.println("glides into the air."); + } + } + public int descend(int meters){ + if(this.flying){ + this.altitude = this.altitude - meters; + System.out.println(this.getName()+" flies downward,altitude "+this.altitude); + } + return this.altitude; + } + public void land(){ + if(flying && this.altitude<=1){ + System.out.println(this.getName()+" lands on the ground."); + } + else{ + System.out.println(this.getName()+" is too high, it can't land!"); + } + + } } diff --git a/Fly.java b/Fly.java new file mode 100644 index 0000000..1b41a51 --- /dev/null +++ b/Fly.java @@ -0,0 +1,9 @@ +public interface Fly { + + public void takeOff(); + public int ascend(int meters); + public void glide(); + public int descend(int meters); + public void land(); + +} diff --git a/Nature.java b/Nature.java index fe104f5..66feaf8 100644 --- a/Nature.java +++ b/Nature.java @@ -13,7 +13,7 @@ public static void main(String[] args) { Eagle hawkeye = new Eagle("Hawkeye"); // TODO : uncomment the following code in order to test it - /* + hawkeye.takeOff(); hawkeye.ascend(120); hawkeye.ascend(30); @@ -22,6 +22,6 @@ public static void main(String[] args) { hawkeye.land(); hawkeye.descend(9); hawkeye.land(); - */ + } } diff --git a/Swim.java b/Swim.java index d76212d..2e8e323 100644 --- a/Swim.java +++ b/Swim.java @@ -7,4 +7,6 @@ public interface Swim { int swimUp(int meters); void getOut(); + + }