Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. /**
  2. * @(#)RPS.java
  3. *
  4. *
  5. * @broncobiker
  6. * @version 1.00 2011/2/21
  7. */
  8.  
  9. import java.util.Scanner;
  10.  
  11. public class RPS {
  12.  
  13. public static void main(String[] args) {
  14.  
  15. //Define the variables for total points
  16.  
  17. double totalpoint1 = 0;
  18. double totalpoint2 = 0;
  19.  
  20. //Present the instructions and the current scores
  21.  
  22. System.out.println("Welcome to Rock, Paper, Scissors. First to 3 points wins!");
  23.  
  24.  
  25. //Set up while loop
  26.  
  27. while (totalpoint1 < 3 && totalpoint2 < 3) {
  28. System.out.println("Currently Player One has " + totalpoint1 + " and Player 2 has " + totalpoint2 + ".");
  29.  
  30.  
  31. //Ask user what they would like to play
  32. Scanner input = new Scanner(System.in);
  33. System.out.println("Would you like to play Rock (0), Paper (1), or Scissors (2)?");
  34. int humanPlay = input.nextInt();
  35.  
  36.  
  37. //Define what the computer chooses to play
  38.  
  39. int computerPlay = (int)(Math.random() * 3);
  40.  
  41. //Compare the two choices and determine who is the winner for each hand
  42. System.out.println("You played " + humanPlay + " the computer played " + computerPlay + ".");
  43.  
  44. if (humanPlay == computerPlay) {
  45. System.out.println("You tied, nothing happens");
  46. }
  47.  
  48. else if (humanPlay == 0 && computerPlay == 1) {
  49. System.out.println("The computer won this round!");
  50. totalpoint2++;
  51. }
  52.  
  53. else if (humanPlay == 0 && computerPlay == 2) {
  54. System.out.println("You won this round!");
  55. totalpoint1++;
  56. }
  57.  
  58. else if (humanPlay == 1 && computerPlay == 0) {
  59. System.out.println("You won this round!");
  60. totalpoint1++;
  61. }
  62.  
  63. else if (humanPlay == 1 && computerPlay == 2) {
  64. System.out.println("The computer won this round!");
  65. totalpoint2++;
  66. }
  67.  
  68. else if (humanPlay == 2 && computerPlay == 0) {
  69. System.out.println("The computer won this round!");
  70. totalpoint2++;
  71. }
  72.  
  73. else if (humanPlay == 2 && computerPlay == 1) {
  74. System.out.println("You won this round!");
  75. totalpoint1++;
  76. }
  77.  
  78.  
  79. }
  80.  
  81.  
  82. if (totalpoint1 == 3 || totalpoint2 == 3) {
  83. System.out.println("The final score is " + totalpoint1 + " for you, and " + totalpoint2 + " for the computer!");
  84.  
  85. if (totalpoint1 > totalpoint2) {
  86. System.out.println("You win!");
  87. }
  88. else if (totalpoint2 > totalpoint1) {
  89. System.out.println("The Computer won!");
  90. }
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement