Guest User

Untitled

a guest
Jun 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.15 KB | None | 0 0
  1. package chapter5;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class PP57 {
  7.  
  8.     public static void main(String[] args) {
  9.         int rock = 1, paper = 2, scissors = 3, computerGuess, userGuess, tieCounter = 0, winCounter = 0, loseCounter = 0;
  10.         Scanner userinput = new Scanner(System.in);
  11.         Random randomGenerator = new Random();
  12.  
  13.         System.out.println("Please enter you guess (1 for rock, 2 for paper and 3 for scissors | You can continue to play untill"
  14.                 + " you press 0 at which case the program will end :D");
  15.  
  16.         while (userinput.hasNextInt()) {
  17.  
  18.  
  19.             //computer's guess
  20.             computerGuess = randomGenerator.nextInt(3) + 1;
  21.  
  22.  
  23.             //user's guess
  24.  
  25.             userGuess = userinput.nextInt();
  26.  
  27.  
  28.  
  29.             //user & computer tie
  30.             if (userGuess == computerGuess) {
  31.                 System.out.println("You tied with the computer!");
  32.                 System.out.println("Your Guess: " + userGuess);
  33.                 System.out.println("Computer's Guess: " + computerGuess);
  34.                 System.out.println("Care to play again? 1 for rock, 2 for paper and 3 for scissors or 0 to end");
  35.                 tieCounter++;
  36.             }
  37.             //user wins
  38.             if (userGuess == 1 && computerGuess == 3) {
  39.                 System.out.println("You have won");
  40.                 System.out.println("Your Guess: " + userGuess);
  41.                 System.out.println("Computer's Guess: " + computerGuess);
  42.                 System.out.println("Care to play again? 1 for rock, 2 for paper and 3 for scissors or 0 to end");
  43.                 winCounter++;
  44.             }
  45.             //user wins
  46.             if (userGuess == 2 && computerGuess == 1) {
  47.                 System.out.println("You have won");
  48.                 System.out.println("Your Guess: " + userGuess);
  49.                 System.out.println("Computer's Guess: " + computerGuess);
  50.                 System.out.println("Care to play again? 1 for rock, 2 for paper and 3 for scissors or 0 to end");
  51.                 winCounter++;
  52.             }
  53.             //user wins
  54.             if (userGuess == 3 && computerGuess == 2) {
  55.                 System.out.println("You have won");
  56.                 System.out.println("Your Guess: " + userGuess);
  57.                 System.out.println("Computer's Guess: " + computerGuess);
  58.                 System.out.println("Care to play again? 1 for rock, 2 for paper and 3 for scissors or 0 to end");
  59.                 winCounter++;
  60.             }
  61.             //computer wins
  62.             if (computerGuess == 1 && userGuess == 3) {
  63.                 System.out.println("You have lost");
  64.                 System.out.println("Your Guess: " + userGuess);
  65.                 System.out.println("Computer's Guess: " + computerGuess);
  66.                 System.out.println("Care to play again? 1 for rock, 2 for paper and 3 for scissors or 0 to end");
  67.                 loseCounter++;
  68.             }
  69.             //computer wins
  70.             if (computerGuess == 2 && userGuess == 1) {
  71.                 System.out.println("You have lost");
  72.                 System.out.println("Your Guess: " + userGuess);
  73.                 System.out.println("Computer's Guess: " + computerGuess);
  74.                 System.out.println("Care to play again? 1 for rock, 2 for paper and 3 for scissors or 0 to end");
  75.                 loseCounter++;
  76.             }
  77.             //computer wins
  78.             if (computerGuess == 3 && userGuess == 2) {
  79.                 System.out.println("You have lost");
  80.                 System.out.println("Your Guess: " + userGuess);
  81.                 System.out.println("Computer's Guess: " + computerGuess);
  82.                 System.out.println("Care to play again? 1 for rock, 2 for paper and 3 for scissors or 0 to end");
  83.                 loseCounter++;
  84.             }
  85.             //invaid wins
  86.             if (userGuess > 3) {
  87.                 System.out.println("Invaild Input | 1 for rock, 2 for paper and 3 for scissors");
  88.  
  89.  
  90.             }
  91.  
  92.             if (userGuess == 0) {
  93.                 System.out.println("Wins:" + winCounter);
  94.                 System.out.println("Wins:" + tieCounter);
  95.                 System.out.println("Wins:" + loseCounter);
  96.                 System.exit(0);
  97.  
  98.             }
  99.  
  100.         }
  101.  
  102.     }
  103. }
Add Comment
Please, Sign In to add comment