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
42 changes: 41 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,44 @@ public boolean isFlying() {
public String sing() {
return "Screech!";
}

@Override
public void takeOff() {
if (!this.flying && this.altitude == 0) {
this.flying = true;
System.out.printf("%s takes off in the sky.%n", this.getName());
}
}

@Override
public void ascend(int meters) {
if (this.flying && meters > 0) {
this.altitude = Math.min(this.altitude + meters, 325);
System.out.printf("%s flies upward, altitude : %d%n", this.getName(), this.altitude);
}
}

@Override
public void glide() {
if (this.flying && this.altitude > 0) {
System.out.printf("%s glides into the air.%n", this.getName());
}
}

@Override
public void descend(int meters) {
if (this.flying && meters > 0) {
this.altitude = Math.max(this.altitude - meters, 1);
System.out.println(this.getName() + " flies downward, altitude : " + this.altitude);
}
}

@Override
public void land () {
if (this.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.");
}
}
}
12 changes: 12 additions & 0 deletions Fly.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public interface Fly {

void takeOff();

void ascend(int meters);

void glide();

void descend(int meters);

void land();
}
3 changes: 0 additions & 3 deletions Nature.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ 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 +20,5 @@ public static void main(String[] args) {
hawkeye.land();
hawkeye.descend(9);
hawkeye.land();
*/
}
}
31 changes: 31 additions & 0 deletions out/production/quest-java-oop3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Created by https://www.gitignore.io/api/java

.idea

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*


# End of https://www.gitignore.io/api/java
14 changes: 14 additions & 0 deletions out/production/quest-java-oop3/quest-java-oop3.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="55b38f44-3562-412e-8d68-f6861e1ec0b4" />
</component>
</module>
14 changes: 14 additions & 0 deletions quest-java-oop3.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="55b38f44-3562-412e-8d68-f6861e1ec0b4" />
</component>
</module>