Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Pool{
- public static void main(String[] args){
- //declare and initialize variables
- int p1Score = 0, p2Score = 0;
- Scanner kb = new Scanner(System.in);
- //Get first ball score
- System.out.print("Enter a ball: ");
- int ball = kb.nextInt();
- //while loop - keep going while neither player has 70 or more
- while( p1Score <= 70 && p2Score <= 70 ){
- //Player 1's turn while ball is not 0
- while( ball != 0 ){
- p1Score += ball;
- //Output new score
- System.out.println("Player1\t" + p1Score + "\tPlayer2\t" + p2Score);
- //Get next ball
- System.out.print("Enter a ball: ");
- ball = kb.nextInt();
- }
- //Get first ball of player 2's turn
- System.out.print("Enter a ball: ");
- ball = kb.nextInt();
- //Player 2's turn while ball is not 0
- while( ball != 0 ){
- p2Score += ball;
- //Output new score
- System.out.println("Player1\t" + p1Score + "\tPlayer2\t" + p2Score);
- //Get next ball
- System.out.print("Enter a ball: ");
- ball = kb.nextInt();
- }
- }
- //End of game if code reaches here
- if( p1Score > p2Score ) System.out.print("Player1 wins " + p1Score + " to " + p2Score);
- else if( p2Score > p1Score ) System.out.print("Player 2 wins " + p2Score + " to " + p1Score);
- else System.out.print("It's a tie " + p1Score + " to " + p2Score);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement