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,34 @@
/*
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
* Date: 2022-03-19
* Description: Dog class
*/
public class Dog extends Animal {
/**
* Constructor. Initialize the name and weight of the dog
*/
public Dog(String name, double weight) {
super(name, weight);
}
/**
* Feeding a dog adds 2.0 to its weight
*/
public void feed() {
setWeight(getWeight() + 2.0);
}
/**
* Test
*/
public static void testDog() {
Dog d = new Dog("Woof", 2.0);
System.out.println(d.getName() == "Woof");
System.out.println(d.getWeight() == 2.0);
d.feed();
// The name is still the same but the weight increased by 2.0:
System.out.println(d.getName() == "Woof");
System.out.println(d.getWeight() == 4.0);
}
}