Files
oop/assignment3/Question2/Rabbit.java
2022-04-11 14:06:40 +08:00

55 lines
950 B
Java

/*
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
* Date: 2022-04-11
* Description: Rabbit class
*/
public class Rabbit extends Mammal {
/**
* The weight of the rabbit.
*/
private double weight;
/**
* Getter for the weight of the rabbit.
*
* @return the weight of the rabbit
*/
public double getWeight() {
return weight;
}
/**
* Constructor.
*
* @param name
* the name of the rabbit
* @param weight
* the weight of the rabbit
*/
public Rabbit(String name, double weight) {
super(name);
this.weight = weight;
}
/**
* Rabbit can be cooked.
*
* return true
*/
@Override
public boolean isCookable() {
return true;
}
/**
* Test.
*/
public static void testRabbit() {
Rabbit rabbit = new Rabbit("Rabbit", 1.0);
System.out.println(rabbit.getName() == "Rabbit");
System.out.println(rabbit.getWeight() == 1.0);
System.out.println(rabbit.isCookable() == true);
}
}