Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. import java.util.*;
  2. //program where you can play Rock, Paper, Scissors against a computer
  3. public class CrocPaperScissors
  4. {
  5. public static void main(String[]cocks)
  6. {
  7. Scanner scan=new Scanner(System.in);
  8. boolean playz=true;
  9. while (playz==true)
  10. {
  11. boolean play=true;
  12. int compCount=0, playCount=0;
  13. while(play==true&&compCount!=3&&playCount!=3)
  14. {
  15. System.out.print("What's your pick?: ");
  16. String pick=scan.next().substring(0,1).toLowerCase();
  17. if(pick.equals("r"))
  18. pick="Rock";
  19. if(pick.equals("s"))
  20. pick="Scissors";
  21. if(pick.equals("p"))
  22. pick="Paper";
  23. String computer;
  24. int choice=(int)(Math.random()*3+1);
  25. if(choice==1)//Rock, 9 combinations
  26. {
  27. computer="Rock";
  28. System.out.print("The computer picked "+computer+": ");
  29. if(pick.equals("Scissors"))
  30. {
  31. System.out.println("You lose this round!");
  32. compCount++;
  33. }
  34. if(pick.equals("Rock"))
  35. System.out.println("Tie.");
  36. if(pick.equals("Paper"))
  37. {
  38. System.out.println("You win this round!");
  39. playCount++;
  40. }
  41. }
  42. if(choice==2)//Scissors, 9 combinations
  43. {
  44. computer="Scissors";
  45. System.out.print("The computer picked "+computer+": ");
  46. if(pick.equals("Paper"))
  47. {
  48. System.out.println("You lose this round!");
  49. compCount++;
  50. }
  51. if(pick.equals("Scissors"))
  52. System.out.println("Tie.");
  53. if(pick.equals("Rock"))
  54. {
  55. System.out.println("You win this round!");
  56. playCount++;
  57. }
  58. }
  59. if(choice==3)//Paper, 9 combinations
  60. {
  61. computer="Paper";
  62. System.out.print("The computer picked "+computer+": ");
  63. if(pick.equals("Rock"))
  64. {
  65. System.out.println("You lose this round!");
  66. compCount++;
  67. }
  68. if(pick.equals("Paper"))
  69. System.out.println("Tie.");
  70. if(pick.equals("Scissors"))
  71. {
  72. System.out.println("You win this round!");
  73. playCount++;
  74. }
  75. }
  76. }
  77. if(compCount==3)
  78. System.out.println("\nComputer Wins!");
  79. if(playCount==3)
  80. System.out.println("\nYou Won!");
  81. System.out.print("\nPlay again?(y/n): ");
  82. String playAgain=scan.next().substring(0,1).toLowerCase();
  83. if(playAgain.equals("y"))
  84. playz=true;
  85. else
  86. playz=false;
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement