Code
/// Name: Afaf Nabeeha
/// Period: 7
/// Program Name: Project 2
/// File Name: Project2.java
/// Date Finished: 1/20/2016 public class Project2
import java.util.Scanner;
public class Project2
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String player1, player2, pileChoice;
int pile1, pile2, pile3, removingNumber, p1, p2;
pile1 = 3;
pile2 = 4;
pile3 = 5;
p1 = 0;
p2 = 0;
System.out.print( "Player 1, enter your name: ");
player1 = keyboard.next();
System.out.print( "Player 2 , enter your name: ");
player2 = keyboard.next();
System.out.println();
System.out.println( "A: " + pile1 + " B: " + pile2 + " C: " + pile3 );
while ( !(pile1 <= 0) || !(pile2 <= 0) || !(pile3 <= 0) )
{
System.out.print( player1 + ", choose a pile: " );
pileChoice = keyboard.next();
if ( pileChoice.equals("A"))
{
System.out.print( "How many to remove from pile A: ");
removingNumber = keyboard.nextInt();
pile1 = pile1 - removingNumber;
System.out.println( "A: " + pile1 + " B: " + pile2 + " C: " + pile3 );
p1++;
}
else if ( pileChoice.equals("B"))
{
System.out.print( "How many to remove from pile B: ");
removingNumber = keyboard.nextInt();
pile2 = pile2 - removingNumber;
System.out.println( "A: " + pile1 + " B: " + pile2 + " C: " + pile3 );
p1++;
}
else if ( pileChoice.equals("C"))
{
System.out.print( "How many to remove from pile C: ");
removingNumber = keyboard.nextInt();
pile3 = pile3 - removingNumber;
System.out.println( "A: " + pile1 + " B: " + pile2 + " C: " + pile3 );
p1++;
}
System.out.print( player2 + ", choose a pile: " );
pileChoice = keyboard.next();
if ( pileChoice.equals("A"))
{
System.out.print( "How many to remove from pile A: ");
removingNumber = keyboard.nextInt();
pile1 = pile1 - removingNumber;
System.out.println( "A: " + pile1 + " B: " + pile2 + " C: " + pile3 );
p2++;
}
else if ( pileChoice.equals("B"))
{
System.out.print( "How many to remove from pile B: ");
removingNumber = keyboard.nextInt();
pile2 = pile2 - removingNumber;
System.out.println( "A: " + pile1 + " B: " + pile2 + " C: " + pile3 );
p2++;
}
else if ( pileChoice.equals("C"))
{
System.out.print( "How many to remove from pile C: ");
removingNumber = keyboard.nextInt();
pile3 = pile3 - removingNumber;
System.out.println( "A: " + pile1 + " B: " + pile2 + " C: " + pile3 );
p2++;
}
}
if ( p1 > p2 )
{
System.out.println( player2 + ", there are no counters left, so you WIN!" );
}
else if ( p1 == p2 )
{
System.out.println( player1 + ", there are no counters left, so you WIN!" );
}
}
}
Picture of the output