fork download
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. /**
  5.   *
  6.   * @author St0ner1995
  7.   */
  8. public class GameRockPaperScissors {
  9.  
  10. /**
  11.   * @param args the command line arguments
  12.   */
  13. public static void main(String[] args) {
  14. String personPlay; //User's play -- "R", "P", or "S"
  15. String computerPlay = ""; //Computer's play -- "R", "P", or "S"
  16. int computerInt; //Randomly generated number used to determine
  17. //computer's play
  18. String response;
  19.  
  20.  
  21. Scanner scan = new Scanner(System.in);
  22. Random generator = new Random();
  23.  
  24. System.out.println("Hey, let's play Rock, Paper, Scissors!\n" +
  25. "Please enter a move.\n" + "Rock = R, Paper" +
  26. "= P, and Scissors = S.");
  27.  
  28. System.out.println();
  29.  
  30. //Generate computer's play (0,1,2)
  31. computerInt = generator.nextInt(3)+1;
  32.  
  33. //Translate computer's randomly generated play to
  34. //string using if //statements
  35.  
  36. if (computerInt == 1)
  37. computerPlay = "R";
  38. else if (computerInt == 2)
  39. computerPlay = "P";
  40. else if (computerInt == 3)
  41. computerPlay = "S";
  42.  
  43.  
  44. //Get player's play from input-- note that this is
  45. // stored as a string
  46. System.out.print("Enter your play: ");
  47. personPlay = scan.next();
  48.  
  49. //Make player's play uppercase for ease of comparison
  50. personPlay = personPlay.toUpperCase();
  51.  
  52. //Print computer's play
  53. System.out.println("Computer play is: " + computerPlay);
  54.  
  55.  
  56. //See who won. Use nested ifs
  57.  
  58. if (personPlay.equals(computerPlay))
  59. System.out.println("It's a tie!");
  60. else if (personPlay.equals("R"))
  61. if (computerPlay.equals("P"))
  62. System.out.println("Paper eats rock. You lose!!");
  63. else if (computerPlay.equals("S"))
  64. System.out.println("Rock crushes scissors. You win!!");
  65. else if (personPlay.equals("P"))
  66. if (computerPlay.equals("R"))
  67. System.out.println("Paper eats rock. You win!!");
  68. else if (computerPlay.equals("S"))
  69. System.out.println("Scissor cuts paper. You lose!!");
  70. else if (personPlay.equals("S"))
  71. if (computerPlay.equals("R"))
  72. System.out.println("Rock breaks scissors. You lose!!");
  73. else if (computerPlay.equals("P"))
  74. System.out.println("Scissor cuts paper. You win!!");
  75. else
  76. System.out.println("Oops, something happened...");
  77.  
  78. }
  79.  
  80. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
R
compilation info
Main.java:8: error: class GameRockPaperScissors is public, should be declared in a file named GameRockPaperScissors.java
 public class GameRockPaperScissors {
        ^
1 error
stdout
Standard output is empty