Answer:
In java:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int monsternum, usernum;
int count = 0;
Random rand = new Random();
String [] monsters = {"wild pikamoo","wild bulbaroar"};
for(int i =0;i<2;i++){
monsternum = rand.nextInt(5);
System.out.print("A "+monsters[i]+" appears! Guess a number between 1 and 5: ");
usernum = input.nextInt();
if(monsternum == usernum){ count++; System.out.println("Congratulations, you caught a "+monsters[i]+"!"); }
else{ System.out.println("You almost had it, but the monster escaped."); }
}
System.out.println("There are no more monsters to encounter!");
System.out.println("You caught "+count+" monsters of 2");
if(count!=2){ System.out.print("Keep training to be the very best!"); }
else{ System.out.print("You're the monster collector master!"); }
}
}
Explanation:
This declares monster and user number as integers
int monsternum, usernum;
Initialize count to 0
int count = 0;
Call the random object
Random rand = new Random();
Create a string array to save the monster names
String [] monsters = {"wild pikamoo","wild bulbaroar"};
Iterate for the 2 monsters
for(int i =0;i<2;i++){
Generate a monster number
monsternum = rand.nextInt(5);
Prompt the user to take a guess
System.out.print("A "+monsters[i]+" appears! Guess a number between 1 and 5: ");
Get user guess
usernum = input.nextInt();
If monster number and user guess are equal, congratulate the user and increase count by 1
<em> if(monsternum == usernum){ count++; System.out.println("Congratulations, you caught a "+monsters[i]+"!"); }
</em>
If otherwise, prompt the user to keep trying
<em> else{ System.out.println("You almost had it, but the monster escaped."); } </em>
<em> }
</em>
Print no monsters again
System.out.println("There are no more monsters to encounter!");
Print number of monsters caught
System.out.println("You caught "+count+" monsters of 2");
Print user score
<em> if(count!=2){ System.out.print("Keep training to be the very best!"); }
</em>
<em> else{ System.out.print("You're the monster collector master!"); }
</em>