Hey y'all, so I needed to create a dice game that wins when there's a pair, but gives the user the option to continue or quit if they don't roll a pair. Please see code below and any assistance is greatly appreciated. The errors are showing in lines 7, 8, 9. Thankies!!
~FLDancingQueen
/*Introduction to Problem Solving and Algorithm Design, Project #4, Nathalie */
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Random;
int numRolls = 0;//number of rolls
int randomNumber1 = new Random().nextInt(6)+1;
int randomNumber2= new Random().nextInt(6)+1;
public class DiceGame {//Game Program
public static void main(String[] args) {//Main Module
out.println(" ************ ");
out.println(" Try your luck and roll a pair!! ");
out.println(" ************ ");
out.println();
out.println("You rolled a " +randomNumber1+ " and a "+randomNumber2);
numRolls++;
while (randomNumber1!=randomNumber2){//while dice don't match give the option
int choice;
out.println("Would you like to try again? Press '1' to Continue or '2' to End");
out.println(" ");//Just wanted a space here
Scanner keyboard=new Scanner(System.in);
switch(choice) {//choice to keep rolling start
case 1:
int randomNumber1 = new Random().nextInt(6)+1;
int randomNumber2=new Random().nextInt(6)+1;
out.println("You rolled a " +randomNumber1+ " and a "+randomNumber2);
numRolls++;
case 2:
out.print("You chose to end the game without winning after");
out.println(numRolls + " tries.");
}//choice to keep rolling end
}//while dice don't match END
out.print("You won after");
out.println(numRolls + " rolls!");
}//Ends Main Module
}//Ends Game Program
~FLDancingQueen
/*Introduction to Problem Solving and Algorithm Design, Project #4, Nathalie */
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Random;
int numRolls = 0;//number of rolls
int randomNumber1 = new Random().nextInt(6)+1;
int randomNumber2= new Random().nextInt(6)+1;
public class DiceGame {//Game Program
public static void main(String[] args) {//Main Module
out.println(" ************ ");
out.println(" Try your luck and roll a pair!! ");
out.println(" ************ ");
out.println();
out.println("You rolled a " +randomNumber1+ " and a "+randomNumber2);
numRolls++;
while (randomNumber1!=randomNumber2){//while dice don't match give the option
int choice;
out.println("Would you like to try again? Press '1' to Continue or '2' to End");
out.println(" ");//Just wanted a space here
Scanner keyboard=new Scanner(System.in);
switch(choice) {//choice to keep rolling start
case 1:
int randomNumber1 = new Random().nextInt(6)+1;
int randomNumber2=new Random().nextInt(6)+1;
out.println("You rolled a " +randomNumber1+ " and a "+randomNumber2);
numRolls++;
case 2:
out.print("You chose to end the game without winning after");
out.println(numRolls + " tries.");
}//choice to keep rolling end
}//while dice don't match END
out.print("You won after");
out.println(numRolls + " rolls!");
}//Ends Main Module
}//Ends Game Program