import java.io.*;import java.util.Scanner;//scanner packageimport java.util.Random;public class Game{ public static void main(String args) { int cmpScore = 0;//Initially computer score will be zero int cmpTotal = 0;//Initially computer total will be zero int humanScores = 0;//Initially human score will be zero int humanTotal = 0;//Initially human total will be zero int dice;//dice of datatype integer boolean gameOverturn = false; boolean turnOvergame = false; char repeat; String input; //giving the input from the input of type string. Scanner scanner = new Scanner(System.in);//giving the input from the keyboard Random sam = new Random(); System.out.println(“YOU WELCOME TO THE GAME OF THE PIG GAME !!!
“); while (gameOverturn == false) { do { dice = sam.nextInt(6) + 1; System.out.println(“Human rolled: ” + dice); if (dice == 1) { humanScores = 0; System.out.print(“Human lose your turn! in this Turn “); System.out.println(“Human total is ” + humanTotal); turnOvergame = true; while(humanTotal < 100); } else { humanScores =humanScores+ dice; System.out.print("Human Score " + humanScores); System.out.println(" If Human hold ,you will have " + humanScores + " points."); System.out.println("Enter 'r' to roll " + "again, 's' to hold."); input = scanner.nextLine(); repeat = input.charAt(0); if (repeat == 'h') break; } } while(turnOvergame == false || dice != 1); humanTotal =humanTotal+ humanScores; System.out.println("Human score is " + humanTotal); humanScores = 0; if (humanTotal >= 100) { System.out.println(“Human WIN!”); gameOverturn = true; while(humanTotal >= 100); } System.out.println(); System.out.println(“It is the computer’s turn.”); do { dice = sam.nextInt(6) + 1; System.out.println(“The computer rolled: ” + dice); if(dice == 1) { cmpScore = 0; System.out.print(“The computer lost its turn!”); System.out.print(” Computer total is ” + cmpTotal); turnOvergame = true; while(cmpTotal < 100); } else { cmpScore =cmpScore+ dice; if(cmpScore >= 20 || (cmpTotal + cmpScore) >= 100) System.out.println(“The computer holds”); turnOvergame = true; } } while(dice != 1 || cmpScore < 20); cmpTotal =cmpTotal+cmpScore; System.out.println("The computer's score is " + cmpTotal + "
"); cmpScore = 0; if (cmpTotal >= 100) { System.out.println(“THIS TIME THE COMPUTER WINS!!!”); gameOverturn = true; while (cmpTotal >= 100); } if(scanner!=null) scanner.close(); } }}