Assignemnt #p2

Code

          /// Name: Holden Ganch
          /// Period: 7
          /// Program Name:  Second Project
          /// File Name: Longer.java
          /// Date Finished: 3/3/2016


    
                   import java.util.Scanner;

public class P2
{
	public static void main( String[] args )
	{
		Scanner keyboard = new Scanner(System.in);
		
		int a = 10, b = 9, c = 8, z, y;
		String P1, P2, x;
        x = " ";
        z = 0;
        
        System.out.println("The object of the game is to not be the person who takes the last pile ");
        System.out.println("And you can take as many as you want from each pile as long as there is that amount ");
        System.out.println("Also when inputting the pile you want to choose from capitalize your answer  ");
        System.out.println("Ex. if i want pile 'A' than i will put in A not a  ");
        System.out.println("Okay lets get started! ");
        System.out.print("Player 1, enter your name: ");
            P1 = keyboard.next();
            System.out.print("Player 2, enter your name: ");
            P2 = keyboard.next();
        
		while ( a >= 0 && b >= 0 && c >= 0 )
		{
           
            z++;
            System.out.println("A: " + a + "    B: " + b + "    C: " + c);
            
        if ( z % 2 == 1 )
        {
            System.out.print(P1 + ", choose a pile: ");
            x = keyboard.next();
            
            if ( x.equals("A"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                a = a - y;
                while ( a < 0 )
                {
                    a = a + y;
                    System.out.println("Try again");
                    System.out.print(P1 + ", choose a pile: ");
                    x = keyboard.next();
                    if ( x.equals("A"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                a = a - y;
                    }
                    
                }
            }
            else if ( x.equals("B"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                b = b - y;
                while ( b < 0 )
                {
                    b = b + y;
                    System.out.println("Try again");
                    System.out.print(P1 + ", choose a pile: ");
                    x = keyboard.next();
                    if ( x.equals("B"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                b = b - y;
                    }
                    
                }
                
            }
            else if ( x.equals("C"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                c = c - y;
               
            }
            else 
            {
                System.out.println("You didn't enter correctly try again.");
            }
        }
        else if ( z % 2 == 0 )
        {
            System.out.print(P2 + ", choose a pile: ");
            x = keyboard.next();
            
            if ( x.equals("A"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                a = a - y;
                while ( a < 0 )
                {
                    a = a + y;
                    System.out.println("Try again");
                    System.out.print(P2 + ", choose a pile: ");
                    x = keyboard.next();
                    if ( x.equals("A"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                a = a - y;
                    }
                    
                }
            }
            else if ( x.equals("B"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                b = b - y;
                while ( b < 0 )
                {
                    b = b + y;
                    System.out.println("Try again");
                    System.out.print(P2 + ", choose a pile: ");
                    x = keyboard.next();
                    if ( x.equals("B"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                b = b - y;
                    }
                    
                }
            }
            else if ( x.equals("C"))
            {
                System.out.print("How many to remove from pile " + x + ": ");
                y = keyboard.nextInt();
                c = c - y;
                
               
            }
            else 
            {
                System.out.println("You didnt enter correctly try again.");
            }
        }               
	}
        if ( z % 2 == 1 )
        {
            System.out.println(P1 + ". There are no more moves so you won");
        }
        if ( z % 2 == 0 )
        {
            System.out.println(P2 + ". There are no more moves so you won");
        }
}
}




    

Picture of the output

Assignment P2