Assignemnt: PROJECT #2 - NIM Code /// Name: Yordan Rashkov /// Period: 7 /// Program Name: project2nim /// File Name: project2nim.java /// Date Finished: 2/16/2016 import java.util.Scanner; import java.util.Random; public class project2nim { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String[] player = new String[2]; int[] pl = new int[3]; pl[0] = r.nextInt(7) + 1; pl[1] = pl[0]+1; pl[2] = pl[1]+1; byte currPAL,chosenpl = 0; Random r = new Random(); int[] pl = new int[3]; String compile = ""; boolean correct = false; int amountTOremove = 0; try { currPAL = 1; System.out.print("Player 1: "); player[0] = keyboard.next(); System.out.println(); System.out.print("Player 2: "); player[1] = keyboard.next(); System.out.println(); while (pl[0]+pl[1]+pl[2]!=0) { System.out.println("A: "+pl[0]+" B: "+pl[1]+" C: "+pl[2]+"\n"); correct = false; do { System.out.print(player[currPAL] + ", choose a pile: "); compile = keyboard.next(); correct = true; switch (compile) { case "A": chosenpl = 0; break; case "B": chosenpl = 1; break; case "C": chosenpl = 2; break; default: correct = false; System.out.println("Choose A, B or C!"); break; } if (pl[chosenpl]==0 && correct) { System.out.println("Chosen pile is empty, choose another one!"); correct = false; } } while (!correct); do { System.out.print("How many to remove from pile? "); amountTOremove = keyboard.nextInt(); correct = true; if (amountTOremove<=0) { System.out.println("It is necessary that you enter a positive number!!!"); correct = false; } if (pl[chosenpl] < amountTOremove && correct) { System.out.println("You have entered way too many! The maximum amount you can remove is "+pl[chosenpl]); correct = false; } if (correct) pl[chosenpl] -= amountTOremove; } while (!correct); if (currPAL==0) currPAL = 1; else currPAL = 0; } System.out.println("Good Job, "+player[currPAL]+"!!!"); if (currPAL==0) currPAL = 1; else currPAL = 0; System.out.println("UH-OH! "+player[currPAL]+"!!!"); } } }