// Flag_1 // using a flag and a sentinel // The user should enter bowling scores. Every time there are two strikes in a row, // congratulate the user! import javax.swing.JOptionPane; public class Flag_1 { public static void main( String[] args ) { int get_number = 0; int strike = 0; // start off without a strike // Prompt the user to enter a score: String numberString = JOptionPane.showInputDialog(null, "Enter your score for this frame (0-10, 11 for a strike, -1 to exit) ", "Input Number Window", JOptionPane.QUESTION_MESSAGE); // Convert the string into an int value get_number = Integer.parseInt(numberString); // use -1 in this case as the sentinel while (get_number != (-1) ) { if (get_number == 11) { // this is a strike System.out.println(" You got a strike!"); // now check the flag used for strike to see if there are two in a row if (strike == 1) { System.out.println(" That makes two strikes in a row! Congratulations!"); strike = 0; }// be sure to set the flag back to 0 or false else strike = 1; } // end of if this is a strike else { System.out.println(" Your score for this frame is " + get_number + "."); strike = 0 ;} // Prompt the user to enter another score: numberString = JOptionPane.showInputDialog(null, "Enter your score for this frame (0-10, 11 for a strike, -1 to exit) ", "Input Number Window", JOptionPane.QUESTION_MESSAGE); // Convert the string into an int value get_number = Integer.parseInt(numberString); } // end of while loop System.exit( 0 ); } // end main } // end of program