/** * Modifies DiceGame1 by including a loop to roll the dice a fixed number of times * and counters to keep track of the number of games won and lost * * @author Anthony Larrain */ import javax.swing.JOptionPane; class DiceGame2{ public static void main( String [] args){ final int NUMBER_OF_ROLLS = 5; int die1,die2,result,won = 0, lost = 0, roll = 1; while( roll <= NUMBER_OF_ROLLS){ die1 = (int)(Math.random() * 6 + 1); die2 = (int)(Math.random() * 6 + 1); result = die1 + die2; System.out.print("Player you rolled " + result); if (result == 7 ){ System.out.println("\tYou won"); won += 1; } else{ System.out.println("\tYou lost"); lost += 1; } JOptionPane.showMessageDialog(null,"Ready to roll ?"); roll += 1; } System.out.println("You won " + won); System.out.println("You lost " + lost); System.exit(0); } }