/* * Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007) * Date: 2022/03/19 * Description: This is the class of Animal. */ public class Animal { /** * Animal's name */ private String name; /** * Animal's weight */ private double weight; /** * Constructor. Initialize the name and weight of the animal. */ public Animal(String name, double weight) { this.name = name; this.weight = weight; } /** * Get the name of the animal. * * @return the name of the animal */ public String getName() { return name; } /** * 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); } }