Write java program that implements a game in which the computer plays against the human.
GAME OF CHANCE RULES:
// Java program to simulate a game of chance between 2 players
import java.util.Random;
import java.util.Scanner;
public class GameOfChance {
// method to return the result of rolling a fair virtual die
public static int dieRoll()
{
Random ran = new Random();
return(ran.nextInt(6)+1);
}
public static void main(String[] args) {
int rounds = 0;
final int MAX_ROUNDS = 10;
int player1_score =0, player2_score=0;
int player1_die, player2_die;
Scanner scan = new Scanner(System.in);
// loop continues at most MAX_ROUNDS rounds
while(rounds < MAX_ROUNDS)
{
rounds++;
// get the die rolls for both the players
player1_die = dieRoll();
player2_die = dieRoll();
System.out.println("ROUND: "+rounds+"\nPlayer1 Score : "+player1_score+" Player2 Score : "+player2_score);
System.out.println("Player 1 rolls : "+player1_die+" Player 2 rolls : "+player2_die);
// update the scores of the players
if(player1_die > player2_die)
{
player1_score += player1_die+player2_die;
}else if(player1_die < player2_die)
{
player2_score += player1_die+player2_die;
}else
{
player1_score -= (player1_die+player2_die);
player2_score -= (player1_die+player2_die);
}
// check if game is over or not
if((player1_score < 0) || (player2_score < 0))
break;
if(rounds > 3 && ((player1_score > 5*player2_score) || (player2_score > 5*player1_score)))
break;
System.out.println("Enter any key to continue... ");
scan.nextLine();
}
scan.close();
System.out.println("\nPlayer1 Score : "+player1_score+" Player2 Score : "+player2_score);
// determine the winner
if(player1_score == player2_score)
System.out.println("Its a tie");
else if(player1_score > player2_score)
System.out.println("Player 1 wins");
else
System.out.println("Player 2 wins");
}
}
//end of program
Output:

Write java program that implements a game in which the computer plays against the human. GAME...