fork download
  1.  
  2. import java.util.Scanner;
  3.  
  4. class RPSLS_SS {
  5.  
  6. public static void main(String[] args) {
  7. Scanner game = new Scanner(System.in);
  8. System.out.println("Choose your attack: rock,paper,scissors,lizard, or spock");
  9. String cool = game.next();
  10. int num_cool = 0;
  11. String computerPlay = null;
  12. String personPlay = null;
  13. if (cool.equals("rock"))
  14. {
  15. System.out.println("You chose rock. Get ready...");
  16. personPlay = ("rock");
  17. }
  18. if (cool.equals("paper"))
  19. {
  20. System.out.println("You chose paper. Get ready...");
  21. personPlay = ("paper");
  22. }
  23. if (cool.equals("scissors"))
  24. {
  25. System.out.println("You chose scissors. Get ready...");
  26. personPlay = "scissors";
  27. }
  28. int range = 3;
  29. int start = 0;
  30. int number = (int)(start + Math.random()*range );
  31. switch (number) {
  32. case 1:
  33. computerPlay = "rock";
  34. break;
  35. case 2:
  36. computerPlay = "paper";
  37. break;
  38. case 3:
  39. computerPlay= "scissors";
  40. break;
  41. default:
  42. break;
  43. }
  44.  
  45. if (personPlay.equals(computerPlay))
  46. System.out.println("It's a tie!");
  47. else if (personPlay.equals("rock"))
  48. if (computerPlay.equals("scissors"))
  49. System.out.println("Rock crushes scissors. You win!!");
  50. else if (computerPlay.equals("paper"))
  51. System.out.println("Paper eats rock. You lose!!");
  52. else if (personPlay.equals("paper"))
  53. if (computerPlay.equals("scissors"))
  54. System.out.println("Scissor cuts paper. You lose!!");
  55. else if (computerPlay.equals("rock"))
  56. System.out.println("Paper eats rock. You win!!");
  57. else if (personPlay.equals("scissors"))
  58. if (computerPlay.equals("paper"))
  59. System.out.println("Scissor cuts paper. You win!!");
  60. else if (computerPlay.equals("rock"))
  61. System.out.println("Rock breaks scissors. You lose!!");
  62. else
  63. System.out.println("Invalid user input.");
  64.  
  65. }
  66.  
  67. }
  68.  
  69.  
Runtime error #stdin #stdout #stderr 0.06s 4386816KB
stdin
rock
stdout
Choose your attack: rock,paper,scissors,lizard, or spock
You chose rock. Get ready...
stderr
Exception in thread "main" java.lang.NullPointerException
	at RPSLS_SS.main(Main.java:48)