Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion Eagle.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Eagle extends Bird {
public class Eagle extends Bird implements Fly {

private boolean flying;
private int altitude;
Expand All @@ -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");
}
}

}
14 changes: 14 additions & 0 deletions Fly.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public interface Fly {

void takeOff();

void ascend(int meters);

void descend(int meters);

void glide();

void land();


}
5 changes: 2 additions & 3 deletions Nature.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -22,6 +21,6 @@ public static void main(String[] args) {
hawkeye.land();
hawkeye.descend(9);
hawkeye.land();
*/

}
}