filipparodriguezz

Untitled

Dec 12th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.  
  6.  
  7.         Scanner keyboard = new Scanner(System.in);
  8.  
  9.         int pileA = 3;
  10.         int pileB = 3;
  11.         int pileC = 3;
  12.  
  13.         String player1;
  14.         String player2;
  15.         String currentPlayer = "";
  16.  
  17.         String pile = " ";
  18.         int remove;
  19.  
  20.         System.out.println("Player 1, enter your name: ");
  21.         player1 = keyboard.next();
  22.  
  23.         System.out.println("Player 2, enter your name: ");
  24.         player2 = keyboard.next();
  25.  
  26.         if (pileA > 0 || pileB > 0 || pileC > 0)
  27.             do {
  28.                 System.out.print(" A:" + pileA);
  29.  
  30.                 System.out.print(" B:" + pileB);
  31.  
  32.                 System.out.print(" C:" + pileC);
  33.  
  34.                 System.out.println("\n" + player1 + ", Choose a pile: ");
  35.                 pile = keyboard.next();
  36.  
  37.                 System.out.println("How many to remove from pile " + pile + ": ");
  38.                 remove = keyboard.nextInt();
  39.  
  40.                 if (pile.equals("A")) {
  41.                     pileA = pileA - remove;
  42.  
  43.  
  44.                 } else if (pile.equals("B")) {
  45.                     pileB = pileB - remove;
  46.  
  47.  
  48.                 } else if (pile.equals("C")) {
  49.                     pileC = pileC - remove;
  50.  
  51.                 }
  52.                 System.out.print("A:" + pileA);
  53.  
  54.                 System.out.print(" B:" + pileB);
  55.  
  56.                 System.out.print(" C:" + pileC);
  57.  
  58.                 System.out.println("\n" + player2 + ", Choose a pile: ");
  59.                 pile = keyboard.next();
  60.  
  61.                 System.out.println("How many to remove from pile " + pile + ": ");
  62.                 remove = keyboard.nextInt();
  63.  
  64.                 if (pile.equals("A")) {
  65.                     pileA = pileA - remove;
  66.  
  67.  
  68.                 } else if (pile.equals("B")) {
  69.                     pileB = pileB - remove;
  70.  
  71.  
  72.                 } else if (pile.equals("C")) {
  73.                     pileC = pileC - remove;
  74.  
  75.                     if (pileA + pileB + pileC == 0 && currentPlayer.equals(player1)) {
  76.                         System.out.println("A: " + pileA + " B: " + pileB + " C: " + pileC);
  77.                         System.out.println("All piles are empty, Good job! " + player1 );
  78.  
  79.                     }else{
  80.                         System.out.println("A: " + pileA + " B: " + pileB + " C: " + pileC);
  81.                         System.out.println("All piles are empty, Good job! " + player2);
  82.                     }
  83.                 }
  84.             } while (pileA > 0 || pileB > 0 || pileC > 0) ;
  85.             }
  86.     }
Advertisement
Add Comment
Please, Sign In to add comment