Files
oop/assignment3/EuropeanRabbit.java
2022-04-11 13:58:33 +08:00

44 lines
1.0 KiB
Java

/*
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
* Date: 2022-04-11
* Description: European rabbit
*/
public class EuropeanRabbit extends Rabbit {
/**
* Constructor.
*
* @param name The name of the Rabbit.
* @param weight The weight of the Rabbit.
*/
public EuropeanRabbit(String name, double weight) {
super(name, weight);
}
/**
* Constructor. With default weight 2.0
*
* @param name The name of the Rabbit.
*/
public EuropeanRabbit(String name) {
this(name, 2.0);
}
/**
* Test.
*/
public static void testEuropeanRabbit() {
// test first constructor
Rabbit rabbit = new EuropeanRabbit("Bugs Bunny");
System.out.println(rabbit.getName() == "Bugs Bunny");
System.out.println(rabbit.getWeight() == 2.0);
System.out.println(rabbit.isCookable() == true);
// test second constructor
Rabbit rabbit2 = new EuropeanRabbit("Daffy Duck", 3.0);
System.out.println(rabbit2.getName() == "Daffy Duck");
System.out.println(rabbit2.getWeight() == 3.0);
System.out.println(rabbit2.isCookable() == true);
}
}