Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. import java.util.Scanner; //Importing Scanner
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5.  
  6. Scanner input = new Scanner(System.in);
  7.  
  8. String player1, player2; // Assigns players to strings
  9. String p1Select, p2Select;
  10. String Rock = "ROCK";
  11. String Paper = "PAPER";
  12. String Scissors = "SCISSORS";
  13.  
  14. System.out.println("Player 1, please type either rock, paper, or scissors.");
  15. player1 = input.nextLine();
  16. p1Select = player1.toUpperCase();
  17. System.out.println("Player 2, please type either rock, paper, or scissors.");
  18. player2 = input.nextLine();
  19. p2Select = player2.toUpperCase();
  20.  
  21. if (!(p1Select.equals(Rock) || p1Select.equals(Paper) || p1Select.equals(Scissors)) &&(!(p2Select.equals(Rock) || p2Select.equals(Paper) || p2Select.equals(Scissors)))){System.out.println("Both players gave an invalid input");}
  22. else if (!(p1Select.equals(Rock) || p1Select.equals(Paper) || p1Select.equals(Scissors))) {
  23. System.out.println("Player 1 made an invalid input!");
  24. }
  25. else if (!(p2Select.equals(Rock) || p2Select.equals(Paper) || p2Select.equals(Scissors))) {
  26. System.out.println("Player 2 made an invalid input!");
  27. }
  28. else if (p1Select.equals(p2Select)) {
  29. System.out.println("It's a tie!");
  30. } else if (p1Select.equals(Rock)) {
  31. if (p2Select.equals(Paper)) {
  32. System.out.println("Player 2 Wins!");
  33. } else
  34. System.out.println("Player 1 Wins!");
  35. } else if (p1Select.equals(Scissors)) {
  36. if (p2Select.equals(Rock)) {
  37. System.out.println("Player 2 Wins!");
  38. } else
  39. System.out.println("Player 1 Wins!");
  40. } else if (p1Select.equals(Paper)) {
  41. if (p2Select.contentEquals(Scissors)) {
  42. System.out.println("Player 2 Wins!");
  43. } else
  44. System.out.println("Player 1 Wins!");
  45. }
  46. input.close();
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement