Hello, I'm doing exercises on Java builders but I have a question.
I have two classes
Main.java
public class Main {
public static void main(String[] args) {
Duck[] d = new Duck[5];
d[0] = new Duck();
d[1] = new Duck();
d[2] = new Duck();
d[3] = new Duck();
d[4] = new Duck();
}
}
Duck.java
public class Duck {
private int amountOfDucks;
public Duck() {
amountOfDucks++;
if(amountOfDucks >= 1 && amountOfDucks <= 3) {
System.out.println("Ha poucos patos na lagoa. Quack!");
}
else if (amountOfDucks >= 4 && amountOfDucks <= 6) {
System.out.println("Ha alguns patos na lagoa. " +
"Quack! Quack!");
}
else {
System.out.println("Ha muitos patos na lagoa!! " +
"Quack! Quack! Quack! Quack...");
}
System.out.println("Quantidade de Patos: "
+ amountOfDucks + "\n");
}
}
I have the output
There are few ducks in the pond. Quack!
Number of Ducks: 1There are few ducks in the pond. Quack!
Number of Ducks: 1There are few ducks in the pond. Quack!
Number of Ducks: 1There are few ducks in the pond. Quack!
Number of Ducks: 1There are few ducks in the pond. Quack!
Number of Ducks: 1
How do I get an output with the number of ducks amountOfDucks
increasing and not just 1?