Close: #1 Lab 7
This commit is contained in:
57
lab/lab7/Question7/Pegasus.java
Normal file
57
lab/lab7/Question7/Pegasus.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
||||
* Date: 2022/04/03
|
||||
* Description: This is the Pegasus class which is a subclass of the Bird class.
|
||||
*/
|
||||
|
||||
public class Pegasus extends Bird {
|
||||
/**
|
||||
* Constructor. Pegasus do not lay eggs, so the eggCount is set to 0.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public Pegasus(String name) {
|
||||
super(name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pegasus have 4 legs.
|
||||
*
|
||||
* @return 4
|
||||
*/
|
||||
@Override
|
||||
public int getLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pegasi do not lay eggs. So the getNumOfEggs method returns 0. And print a
|
||||
* message to console.
|
||||
*/
|
||||
@Override
|
||||
public int getNumOfEggs() {
|
||||
System.out.println("Pegasi do not lay eggs!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pegasus can fly. So the getFlyingAbility method returns true.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
public boolean canFly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
public static void testPegasus() {
|
||||
Pegasus p = new Pegasus("Pegasus");
|
||||
System.out.println(p.getName() == "Pegasus");
|
||||
System.out.println(p.getLegs() == 4);
|
||||
System.out.println(p.getNumOfEggs() == 0);
|
||||
System.out.println(p.canFly() == true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user