Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public class RockPaperScissors {
  2. public static void main(String[] args) {
  3. Scanner cin = new Scanner(System.in);
  4. System.out.printf(createHeader());
  5. String input = cin.nextLine();
  6. int userGuess = Integer.parseInt(input);
  7. if (userGuess > 3 || userGuess < 1) {
  8. System.out.println("\t\tNot a valid integer, Goodbye");
  9. System.exit(0);
  10. }
  11. Random random = new Random();
  12. int computerGuess = (random.nextInt(3) + 1);
  13. if ((userGuess == 1 && computerGuess == 2) || (userGuess == 2 && computerGuess == 3) || (userGuess == 3 && computerGuess == 1)) {
  14. System.out.println("---> You Lose");
  15. } else if ((userGuess == 1 && computerGuess == 3) || (userGuess == 2 && computerGuess == 1) || (userGuess == 3 && computerGuess == 2)) {
  16. System.out.println("---> You Win");
  17. } else
  18. System.out.println("---> Tie");
  19. if (computerGuess == 1) {
  20. System.out.println("Computer guess: ROCK");
  21. } else if (computerGuess == 2) {
  22. System.out.println("Computer guess: PAPER");
  23. } else if (computerGuess == 3)
  24. System.out.println("Computer guess: SCISSORS");
  25. //end main
  26. }
  27. //Output section
  28. public static String createHeader() {
  29. String output = "";
  30. output += "*******************************\n";
  31. output += "*******************************\n";
  32. output += "*****Rock, Paper, Scissors!****\n";
  33. output += "*******************************\n";
  34. output += "*******************************\n\n";
  35. output += "Computer has its guess!\n";
  36. output += "Enter your guess: Rock, Paper, Scissors [1, 2, or 3]:";
  37. return output;
  38. } // end class
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement