package lab1;

import java.util.Random;
import java.util.Scanner;

public class Game {

    public static void main(String[] args) {
        new Game().startGame();
    }

    public Random random = new Random();
    public Scanner scanner = new Scanner(System.in);
    public int playerWins = 0;
    public int computerWins = 0;

    public Game() {}

    public void startGame() {
        while (playerWins < 2 && computerWins < 2) {
            playRound();
        }
        System.out.println("The " + (playerWins > computerWins ? "Player" : "Computer") + " has won.");
    }

    public void playRound() {
        int playerInput = getInput();
        int computerInput = random.nextInt(3);
        System.out.print("The computer is " + getActionName(computerInput) + ". You are " + getActionName(playerInput) + ". ");
        switch (Integer.compare(playerInput, computerInput)) {
            case -1:
                System.out.println("You lose.");
                computerWins++;
                break;
            case 0:
                System.out.println("It's a draw.");
                break;
            case 1:
                System.out.println("You win.");
                playerWins++;
                break;
        }
    }

    public String getActionName(int action) {
        switch (action) {
            case 0:
                return "Scissor";
            case 1:
                return "Rock";
            case 2:
                return "Paper";
            default:
                return "Error";
        }
    }

    public int getInput() {
        int input = -1;
        while (input < 0 || input > 2) {
            System.out.print("\nscissor (0), rock (1), paper (2): ");
            input = scanner.nextInt();
        }
        return input;
    }
}

@@ -143,16 +143,17 @@
 ew Game(
+2
 ).startG
@@ -260,16 +260,50 @@
 em.in);%0A
+    public int winThreshold = 2;%0A%0A
     publ
@@ -375,19 +375,82 @@
 ic Game(
-) %7B
+int winThreshold) %7B%0A        this.winThreshold = winThreshold;%0A    
 %7D%0A%0A    p
@@ -487,17 +487,25 @@
    while
- 
+(Math.max
 (playerW
@@ -511,15 +511,9 @@
 Wins
- %3C 2 &&
+,
  com
@@ -525,12 +525,24 @@
 Wins
+)
  %3C 
-2
+winThreshold
 ) %7B%0A
@@ -568,32 +568,33 @@
 nd();%0A        %7D%0A
+%0A
         System.o
@@ -747,21 +747,28 @@
 ut = get
-Input
+PlayerAction
 ();%0A    
@@ -810,16 +810,17 @@
 Int(3);%0A
+%0A
         
@@ -935,24 +935,25 @@
 t) + %22. %22);%0A
+%0A
         swit
@@ -958,25 +958,22 @@
 itch
- (Integer.
+(
 compare
+Action
 (pla
@@ -1373,142 +1373,205 @@
 lic 
-Str
 in
-g
+t
  get
-ActionName(int action) %7B%0A        switch (action) %7B%0A            case 0:%0A                return %22Scissor%22;%0A            case 1:
+PlayerAction() %7B%0A        int input = -1;%0A%0A        while(input %3C 0 %7C%7C input %3E 2) %7B%0A            System.out.print(%22%5Cnscissor (0), rock (1), paper (2): %22);%0A            input = scanner.nextInt();
 %0A   
@@ -1567,32 +1567,35 @@
 tInt();%0A        
+%7D%0A%0A
         return %22
@@ -1597,66 +1597,121 @@
 urn 
-%22Rock%22
+input
 ;%0A    
+%7D%0A%0A
     
-    case 2:%0A                return %22Pap
+public static int compareAction(int player, int computer) %7B%0A        int key = player - comput
 er
-%22
 ;%0A  
@@ -1720,62 +1720,75 @@
     
-    
-default:%0A                return %22Error%22;%0A        %7D
+return key == 0 ? 0 : key == 1 %7C%7C key == -2 ? 1 : -1; // Witchcraft
 %0A   
@@ -1806,217 +1806,264 @@
 lic 
+static Str
 in
-t
+g
  get
-Input() %7B%0A        int input = -1;%0A        while (input %3C 0 %7C%7C input %3E 2) %7B%0A            System.out.print(%22%5Cnscissor (0), rock (1), paper (2): %22);%0A            input = scanner.nextInt();%0A        %7D%0A
+ActionName(int action) %7B%0A        switch(action) %7B%0A            case 0:%0A                return %22Scissor%22;%0A            case 1:%0A                return %22Rock%22;%0A            case 2:%0A                return %22Paper%22;%0A            default:%0A   
         
 retu
@@ -2054,34 +2054,51 @@
 %0A           
+     
 return 
-input;
+%22Error%22;%0A        %7D
 %0A    %7D%0A%7D%0A

Use a better compare