/* * This program will play a simple dice game. * * 7 or 11 you win, * 2,3 or 12 you loose, * Any other number it's a tie. * * The game will loop to allow the user to play as often as desired. * * @author Anthony Larrain */ import java.util.Scanner; class DiceGame3{ public static void main( String [] args){ Scanner input = new Scanner(System.in); //counters to keep track of the outcome int won = 0, lost = 0, tied = 0; // for the users response char playRound = 'y'; while(playRound == 'y' || playRound == 'Y'){ int die1 = (int)(Math.random() * 6 + 1); int die2 = (int)(Math.random() * 6 + 1); int result = die1 + die2; System.out.print("Player you rolled " + result); if (result == 7 || result == 11 ){ System.out.println("\tYou won"); ++won; } else if ( result == 2 || result == 3 || result == 12) { System.out.println("\tYou lost"); ++lost; } else { System.out.println("\tYou tied "); ++tied; } System.out.println("Play again ? (Y/N)"); String userResponse = input.next(); playRound = userResponse.charAt(0); } System.out.print("\nYou won " + won); System.out.print("\tYou tied " + tied); System.out.println("\tYou lost " + lost); } }