Advertisement
Guest User

Rockpaperscissor

a guest
Sep 18th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.75 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         int playerScore = 0;
  8.         int computerScore =0;
  9.         boolean running = true;
  10.         String[] outcomes = new String[3];
  11.         outcomes[0] = "Rock";
  12.         outcomes[1] = "Scissor";
  13.         outcomes[2] = "Paper";
  14.         Scanner scan = new Scanner(System.in);
  15.         String playerChoice,computerChoice;
  16.  
  17.         while(running) {
  18.             System.out.println("Rock, paper or scissors, make your choice.");
  19.             System.out.println(".....................................................");
  20.  
  21.             playerChoice = scan.nextLine();
  22.             if (playerChoice.equals("Rock")) {
  23.                 playerChoice = outcomes[0];
  24.             } else if (playerChoice.equals("Paper")) {
  25.                 playerChoice = outcomes[2];
  26.             } else if (playerChoice.equals("Scissor")) {
  27.                 playerChoice = outcomes[1];
  28.             }else if(playerChoice.equals("0")) {
  29.                 running = false;
  30.                 break;
  31.             }
  32.  
  33.  
  34.             Random randomno = new Random();
  35.             int randomInt = randomno.nextInt(3);
  36.             computerChoice = outcomes[randomInt];
  37.  
  38.             System.out.println("Computers choice: " + computerChoice);
  39.             System.out.println("Your choice: " + playerChoice);
  40.  
  41.             if (computerChoice.equals(playerChoice)) {
  42.                 System.out.println("Result: Draw");
  43.             } else if (playerChoice == outcomes[0] && computerChoice == outcomes[1]) {
  44.                 System.out.println("Result: Player wins");
  45.                 playerScore++;
  46.             } else if (computerChoice == outcomes[0] && playerChoice == outcomes[1]) {
  47.                 System.out.println("Result: Computer wins");
  48.                 computerScore++;
  49.             } else if (playerChoice == outcomes[2] && computerChoice == outcomes[0]) {
  50.                 System.out.println("Result: Player wins");
  51.                 playerScore++;
  52.             } else if (playerChoice == outcomes[0] && computerChoice == outcomes[2]) {
  53.                 System.out.println("Result: Computer wins");
  54.                 computerScore++;
  55.             } else if (playerChoice == outcomes[2] && computerChoice == outcomes[1]) {
  56.                 System.out.println("Result: Computer wins");
  57.                 computerScore++;
  58.             } else if (playerChoice == outcomes[1] && computerChoice == outcomes[2]) {
  59.                 System.out.println("Result: Player wins");
  60.                 playerScore++;
  61.             }
  62.             System.out.print("Current scores are: ");
  63.             System.out.print("Computer: " + computerScore + " Player: " + playerScore);
  64.             System.out.println();
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement