The problem is to write the paragraph 5 different times. Each paragraph has a different cage number and corresponding animal. So cage 1 has a lion and cage 2 has a tiger. The problem is I don’t know how to combine both the cage number the different corresponding animal in the same paragraph.
I don’t know how to enter the switch statement in the second line of the paragraph. I tried writing println(“This cage holds a ” + i); but Eclipse gave me an error. How do i incorporate both variables n and i in the same paragraph at the same time?
import acm.program.*;
public class ZooAnimals extends ConsoleProgram {
private static final int START = 1;
public void run(){
for (int n = START; n <=5; n++ ) {
println("This animal is in cage" + n);
println("This cage holds a " ); <---- type of animal goes in here.
println("Wild animals are very dangerous.");
}
for(int i = START; i<=5; i++) {
switch(i) {
case 1: println("lion");
case 2: println("tiger");
case 3: println("elephant");
case 4: println("snakes");
case 5: println("hippo");
}
}
}
}
I would write a small method like so:
I would then replace this code:
with this: