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
37 changes: 36 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,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!");
}

}
}
9 changes: 9 additions & 0 deletions Fly.java
Original file line number Diff line number Diff line change
@@ -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();

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

}
}
2 changes: 2 additions & 0 deletions Swim.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface Swim {
int swimUp(int meters);

void getOut();


}