esha492

josh

May 9th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3. import java.util.Random;
  4.  
  5. public class PSR {
  6. public static void main(String[] args)
  7. {
  8. String personPlay; //User's play -- "R", "P", or "S"
  9. String computerPlay = ""; //Computer's play -- "R", "P", or "S"
  10. int computerInt;
  11. String response;
  12.  
  13.  
  14. Scanner scan = new Scanner(System.in);
  15. Random generator = new Random();
  16.  
  17. System.out.println("Hey, let's play Rock, Paper, Scissors!\n" +
  18. "Please enter a move.\n" + "Rock = R, Paper" +
  19. "= P, and Scissors = S.");
  20.  
  21. System.out.println();
  22.  
  23. //Generate computer's play (0,1,2)
  24. computerInt = generator.nextInt(3)+1;
  25.  
  26.  
  27. if (computerInt == 1)
  28. computerPlay = "R";
  29. else if (computerInt == 2)
  30. computerPlay = "P";
  31. else if (computerInt == 3)
  32. computerPlay = "S";
  33.  
  34.  
  35. System.out.println("Enter your play: ");
  36. personPlay = scan.next();
  37.  
  38. personPlay = personPlay.toUpperCase();
  39.  
  40. System.out.println("Computer play is: " + computerPlay);
  41.  
  42.  
  43. if (personPlay.equals(computerPlay)) {
  44. System.out.println("It's a tie!");
  45. } else if (personPlay.equals("R")) {
  46. if (computerPlay.equals("S")) {
  47. System.out.println("Rock crushes scissors. You win!!");
  48. } else if (computerPlay.equals("P"))
  49. System.out.println("Paper eats rock. You lose!!");
  50. } else if (personPlay.equals("P")) {
  51. if (computerPlay.equals("S")) {
  52. System.out.println("Scissor cuts paper. You lose!!");
  53. } else if (computerPlay.equals("R"))
  54. System.out.println("Paper eats rock. You win!!");
  55. } else if (personPlay.equals("S")) {
  56. if (computerPlay.equals("P")) {
  57. System.out.println("Scissor cuts paper. You win!!");
  58. } else if (computerPlay.equals("R"))
  59. System.out.println("Rock breaks scissors. You lose!!");
  60. } else {
  61. System.out.println("Invalid user input.");
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment