This commit is contained in:
2022-03-19 17:47:52 +08:00
parent 6bf672bd5b
commit 1c8f95c4b3
35 changed files with 1597 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
/*
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
* Date: 2022-03-19
* Description: Cat class
*/
public class Cat extends Animal {
/**
* Constructor. Initialize the name and weight of the cat
*/
public Cat(String name, double weight) {
super(name, weight);
}
/**
* Feeding a cat adds 1.0 to its weight
*/
public void feed() {
setWeight(getWeight() + 1.0);
}
/**
* Test
*/
public static void testCat() {
Cat c = new Cat("Meow", 2.0);
System.out.println(c.getName() == "Meow");
System.out.println(c.getWeight() == 2.0);
c.feed();
// The name is still the same but the weight increased by 1.0:
System.out.println(c.getName() == "Meow");
System.out.println(c.getWeight() == 3.0);
}
}