Restore
This commit is contained in:
10
Labs/Lab7/Lab7_2230026071/Question4/.classpath
Normal file
10
Labs/Lab7/Lab7_2230026071/Question4/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
Labs/Lab7/Lab7_2230026071/Question4/.project
Normal file
17
Labs/Lab7/Lab7_2230026071/Question4/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Question4</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Animal.class
Normal file
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Animal.class
Normal file
Binary file not shown.
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Bird.class
Normal file
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Bird.class
Normal file
Binary file not shown.
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Dog.class
Normal file
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Dog.class
Normal file
Binary file not shown.
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Magpie.class
Normal file
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Magpie.class
Normal file
Binary file not shown.
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Start.class
Normal file
BIN
Labs/Lab7/Lab7_2230026071/Question4/bin/Start.class
Normal file
Binary file not shown.
21
Labs/Lab7/Lab7_2230026071/Question4/src/Animal.java
Normal file
21
Labs/Lab7/Lab7_2230026071/Question4/src/Animal.java
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
public abstract class Animal {
|
||||
//instance variable
|
||||
private String name;
|
||||
|
||||
//constructor
|
||||
public Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//methods
|
||||
public String getName() {return this.name;}
|
||||
|
||||
//abstract methods
|
||||
public abstract int getLegs();
|
||||
|
||||
public abstract boolean canFly();
|
||||
|
||||
//test
|
||||
public static void testAnimal() {}
|
||||
}
|
||||
24
Labs/Lab7/Lab7_2230026071/Question4/src/Bird.java
Normal file
24
Labs/Lab7/Lab7_2230026071/Question4/src/Bird.java
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
public abstract class Bird extends Animal{
|
||||
//instance variable
|
||||
private int numOfEggs;
|
||||
|
||||
//constructor
|
||||
public Bird(String name, int numOfEggs) {
|
||||
super(name);
|
||||
this.numOfEggs = numOfEggs;
|
||||
}
|
||||
|
||||
//methods
|
||||
public int getNumOfEggs() {return this.numOfEggs;}
|
||||
|
||||
//methods override
|
||||
@Override
|
||||
public int getLegs() {return 2;}
|
||||
|
||||
@Override
|
||||
public abstract boolean canFly();
|
||||
|
||||
//test
|
||||
public static void testBird() {}
|
||||
}
|
||||
24
Labs/Lab7/Lab7_2230026071/Question4/src/Dog.java
Normal file
24
Labs/Lab7/Lab7_2230026071/Question4/src/Dog.java
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
public class Dog extends Animal{
|
||||
//constructor
|
||||
public Dog(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
//methods override
|
||||
@Override
|
||||
public int getLegs() {return 4;}
|
||||
|
||||
@Override
|
||||
public boolean canFly() {return false;}
|
||||
|
||||
//test
|
||||
public static void testDog() {
|
||||
Dog d = new Dog("Nice Doggy");
|
||||
// The getName method is inherited from Animal.
|
||||
// The getLegs and canFly methods come from Dog itself.
|
||||
System.out.println(d.getName() == "Nice Doggy");
|
||||
System.out.println(d.getLegs() == 4);
|
||||
System.out.println(d.canFly() == false);
|
||||
}
|
||||
}
|
||||
20
Labs/Lab7/Lab7_2230026071/Question4/src/Magpie.java
Normal file
20
Labs/Lab7/Lab7_2230026071/Question4/src/Magpie.java
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
public class Magpie extends Bird{
|
||||
//constructor
|
||||
public Magpie(String name) {
|
||||
super(name, 6);
|
||||
}
|
||||
|
||||
//method
|
||||
@Override
|
||||
public boolean canFly() {return true;}
|
||||
|
||||
//test
|
||||
public static void testMagpie() {
|
||||
Magpie m = new Magpie("Maggie");
|
||||
System.out.println(m.getName() == "Maggie");
|
||||
System.out.println(m.getLegs() == 2);
|
||||
System.out.println(m.getNumOfEggs() == 6);
|
||||
System.out.println(m.canFly() == true);
|
||||
}
|
||||
}
|
||||
11
Labs/Lab7/Lab7_2230026071/Question4/src/Start.java
Normal file
11
Labs/Lab7/Lab7_2230026071/Question4/src/Start.java
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
public class Start {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Animal.testAnimal();
|
||||
Dog.testDog();
|
||||
Bird.testBird();
|
||||
Magpie.testMagpie();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user