diff --git a/Eagle.java b/Eagle.java index d0e8799..a701c0b 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,45 @@ public boolean isFlying() { public String sing() { return "Screech!"; } + + @Override + public void takeOff() { + if (!this.flying) { + this.flying = true; + System.out.println(this.getName() + "has successfully take off and is now flying"); + } + + } + + @Override + public void land() { + if (this.flying && (this.altitude <= 1)) { + this.flying = false; + System.out.println(this.getName() + " has land on the floor"); + } + } + + @Override + public void ascend(int meters) { + if (this.flying) { + this.altitude = this.altitude + meters; + System.out.println(this.getName() + " is now flying at " + this.altitude); + } + } + + @Override + public void descend(int meters) { + if (this.flying) { + this.altitude = this.altitude - meters; + System.out.println(this.getName() + " is now flying at " + this.altitude); + } + } + + @Override + public void glide() { + if (this.flying) { + System.out.println("the bird is chilling in the air"); + } + } + } diff --git a/Fly.java b/Fly.java new file mode 100644 index 0000000..e786f69 --- /dev/null +++ b/Fly.java @@ -0,0 +1,14 @@ +public interface Fly { + + void takeOff(); + + void ascend(int meters); + + void descend(int meters); + + void glide(); + + void land(); + + +} diff --git a/Nature.java b/Nature.java index fe104f5..d180b2d 100644 --- a/Nature.java +++ b/Nature.java @@ -12,8 +12,7 @@ public static void main(String[] args) { pingou.getOut(); 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 +21,6 @@ public static void main(String[] args) { hawkeye.land(); hawkeye.descend(9); hawkeye.land(); - */ + } }