Project2

Code

import java.util.Scanner;

public class Project2
{
	public static void main( String[] args )
	{
		Scanner keyboard = new Scanner(System.in);
        
        int a, b, c, x, num1, num2;
        String name1, name2, z, y, ANS, WIN;
        
        a = 3;
        b = 4;
        c = 5;
        
        System.out.println(" Hello please enter your name player1 " );
        name1 = keyboard.next();
        
        System.out.println(" Hello please enter your name player2 " );
        name2 = keyboard.next();
        
        ANS = name1;
        WIN = name2;
        
        while ( a>0 || b>0 || c>0 )
        {
            System.out.println(" Okay lets begin " + "A." + a + "  B." + b + "  C." + c );
            System.out.println("please choose a pile " + ANS );
            z = keyboard.next();
            System.out.println("  " );
            System.out.println("  " );
            System.out.println(" Now choose how much you would like to remove " );
            x = keyboard.nextInt();
            
            if ( z.equals("a"))
            {
                a=a-x;
            }
            else if ( z.equals("b"))
            {
                b=b-x;
            }
            else if (z.equals("c"))
            {
                c=c-x;
            }
            
            if ( ANS == name1 )
            {
                ANS = name2;
                WIN = name1;
            }
            else if ( ANS == name2 )
            {
                ANS = name1;
                WIN = name2;
            }
            
                
            
        }
        System.out.println(" The winner is " + ANS );
    }
}

Project2

Project 2