53 lines
1.0 KiB
Java
53 lines
1.0 KiB
Java
/*
|
|
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
|
* Date: 2022/03/19
|
|
* Description: This is the class of Animal.
|
|
*/
|
|
|
|
public class Animal extends LivingThing {
|
|
/**
|
|
* Animal's weight
|
|
*/
|
|
private double weight;
|
|
|
|
/**
|
|
* Constructor. Initialize the name and weight of the animal.
|
|
*/
|
|
public Animal(String name, double weight) {
|
|
super(name);
|
|
this.weight = weight;
|
|
}
|
|
|
|
/**
|
|
* Get the weight of the animal.
|
|
*
|
|
* @return the weight of the animal
|
|
*/
|
|
public double getWeight() {
|
|
return weight;
|
|
}
|
|
|
|
/**
|
|
* Set the weight of the animal.
|
|
*
|
|
* @param weight
|
|
* the weight of the animal
|
|
*/
|
|
public void setWeight(double weight) {
|
|
this.weight = weight;
|
|
}
|
|
|
|
/**
|
|
* Test
|
|
*/
|
|
public static void testAnimal() {
|
|
Animal animal = new Animal("cat", 1.0);
|
|
System.out.println(animal.getName() == "cat");
|
|
System.out.println(animal.getWeight() == 1.0);
|
|
animal.setWeight(2.0);
|
|
System.out.println(animal.getName() == "cat");
|
|
System.out.println(animal.getWeight() == 2.0);
|
|
}
|
|
}
|
|
|