cleancode_game_2

mail@pastecode.io avatar
unknown
java
a month ago
1.0 kB
16
Indexable
Never
public class Animal {
    private String name;
    private int age;
    private String type;

    public Animal(String name, int age, String type) {
        this.name = name;
        this.age = age;
        this.type = type;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getType() {
        return type;
    }

    public String toString() {
        return "Animal [name=" + name + ", age=" + age + ", type=" + type + "]";
    }

    public void makeSound() {
        if (type.equals("dog")) {
            System.out.println("Woof!");
        } else if (type.equals("cat")) {
            System.out.println("Meow!");
        } else {
            System.out.println("Unknown sound!");
        }
    }
}