a3 move to Question1
This commit is contained in:
54
assignment3/Question1/Rabbit.java
Normal file
54
assignment3/Question1/Rabbit.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user