Advertisement
Guest User

Untitled

a guest
Nov 8th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class gameRPS1
  4. {
  5. public static void main(String[] args)
  6. {
  7. private final int ROUNDS = 3;
  8. private int roundCount = 0;
  9.  
  10.  
  11. //creat instance of scanner
  12.  
  13. Scanner keyboardIn = new Scanner(System.in);
  14.  
  15.  
  16.  
  17. //declare variables
  18.  
  19. int userChoice;
  20.  
  21. while(roundCound < ROUNDS){
  22. roundCount++;
  23.  
  24. System.out.println("Make Your Choice:\n 1 Rock\n 2 Paper\n 3 Cissors\n ");
  25. userChoice = keyboardIn.nextInt();
  26.  
  27. if(userChoice == 1 ){
  28. System.out.println("Rock is Your Choice");
  29.  
  30. if(userChoice == 2 )
  31. System.out.println("Paper is Your Choice");
  32.  
  33. if(userChoice == 3 )
  34. System.out.println(" Scissors is Your Choice");
  35. }
  36. if(userChoice > 3 || userChoice < 0 ){
  37. System.out.println("Invalid Choice Please Select Any Of The Above");
  38. }
  39.  
  40. else
  41. {
  42. System.out.println();
  43. }
  44.  
  45. String [] arr = {"Rock", "Paper", "Scissors"};
  46. Random compChoice = new Random();
  47.  
  48. int select = compChoice.nextInt(arr.length);
  49. System.out.println("Computer choice is : " + arr[select]);
  50.  
  51.  
  52. if(userChoice == 2 && arr[select] == "Rock" ||userChoice == 1 && arr[select] == "Scissors" || userChoice == 3 && arr[select] == "Paper"){
  53. System.out.print("YOU WIN WELL DONE!!!");
  54. }
  55. if(userChoice == 3 && arr[select] == "Rock" ||userChoice == 2 && arr[select] == "Scissors" || userChoice == 1 && arr[select] == "Paper"){
  56. System.out.print("Ooops You Lost!!!");
  57. }
  58. else if(userChoice == 2 && arr[select] == "Paper" ||userChoice == 1 && arr[select] == "Rock" || userChoice == 3 && arr[select] == "Scissors"){
  59. System.out.println("It a tie");
  60. }
  61. else
  62. System.out.println(" Play Again");
  63. }
  64. System.out.println("GAME OVER");
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement