Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @(#)RPS.java
- *
- *
- * @broncobiker
- * @version 1.00 2011/2/21
- */
- import java.util.Scanner;
- public class RPS {
- public static void main(String[] args) {
- //Define the variables for total points
- double totalpoint1 = 0;
- double totalpoint2 = 0;
- //Present the instructions and the current scores
- System.out.println("Welcome to Rock, Paper, Scissors. First to 3 points wins!");
- //Set up while loop
- while (totalpoint1 < 3 && totalpoint2 < 3) {
- System.out.println("Currently Player One has " + totalpoint1 + " and Player 2 has " + totalpoint2 + ".");
- //Ask user what they would like to play
- Scanner input = new Scanner(System.in);
- System.out.println("Would you like to play Rock (0), Paper (1), or Scissors (2)?");
- int humanPlay = input.nextInt();
- //Define what the computer chooses to play
- int computerPlay = (int)(Math.random() * 3);
- //Compare the two choices and determine who is the winner for each hand
- System.out.println("You played " + humanPlay + " the computer played " + computerPlay + ".");
- if (humanPlay == computerPlay) {
- System.out.println("You tied, nothing happens");
- }
- else if (humanPlay == 0 && computerPlay == 1) {
- System.out.println("The computer won this round!");
- totalpoint2++;
- }
- else if (humanPlay == 0 && computerPlay == 2) {
- System.out.println("You won this round!");
- totalpoint1++;
- }
- else if (humanPlay == 1 && computerPlay == 0) {
- System.out.println("You won this round!");
- totalpoint1++;
- }
- else if (humanPlay == 1 && computerPlay == 2) {
- System.out.println("The computer won this round!");
- totalpoint2++;
- }
- else if (humanPlay == 2 && computerPlay == 0) {
- System.out.println("The computer won this round!");
- totalpoint2++;
- }
- else if (humanPlay == 2 && computerPlay == 1) {
- System.out.println("You won this round!");
- totalpoint1++;
- }
- }
- if (totalpoint1 == 3 || totalpoint2 == 3) {
- System.out.println("The final score is " + totalpoint1 + " for you, and " + totalpoint2 + " for the computer!");
- if (totalpoint1 > totalpoint2) {
- System.out.println("You win!");
- }
- else if (totalpoint2 > totalpoint1) {
- System.out.println("The Computer won!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement