how do i put a new input in when the compiler runs with the first value?

There were loads of errors in your ActionClass class. I’ve fixed it here:

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

public class ActionClass {

    int winCounter = 0;
    int loseCounter = 0;                  //COUNTER VARIABLES
    int tieCounter = 0;

    public void method() {
        String[] selection = {"Rock", "Paper", "Scissors"};
        Random rand = new Random();                                                  // VARIABLES
        Scanner scanny = new Scanner(System.in);
        char inputChar = scanny.nextLine().charAt(0);
        char playerSelection = Character.toLowerCase(inputChar);

        while (playerSelection != 'q') {
            String opponentSelection = selection[rand.nextInt(3)];
            if (playerSelection == 'q') {
                System.out.println("===============================================================================");
                System.out.println("THANK YOU FOR PLAYING TAKE CARE!!!");
                System.out.println("==============================================================================");
                System.exit(0);
            } else if (playerSelection == 'r') {
                System.out.println("you said " + selection[0] + "\t\t\t\t\t\t\t\t\t\t\t Your opponent chooses... " + opponentSelection);
                System.out.println("======================================================================================================================================================");
            } else if (playerSelection == 'p')
                System.out.println("you said " + selection[1] + "\t\t\t\t\t\t\t\t\t\t\t Your opponent chooses... " + opponentSelection);

            else if (playerSelection == 's')
                System.out.println("you said " + selection[2] + "\t\t\t\t\t\t\t\t\t\t\t Your opponent chooses... " + opponentSelection);

            else System.out.println("\nSorry please select a valid option of ROCK, PAPER or SCISSORS");

            if (opponentSelection.equals(selection[0])) {
                System.out.println("you TIED");
                tieCounter++;
            }
            if (opponentSelection.equals(selection[1])) {
                System.out.println("you LOSE");
                loseCounter++;
            }
            if (opponentSelection.equals(selection[2])) {
                System.out.println("you WIN");
                winCounter++;
            }
            if ((inputChar == 'r') || inputChar == 'p' || inputChar == 's') {
                System.out.println("Good Game!!!");
                System.out.println("\n\n\t\t\t\t\tPlay again!! please select either Rock, Paper or Scissors...");
                System.out.println("\n\t\t\t\t\tYou've WON: " + winCounter + " times!!!" + "You\'ve TIED " + tieCounter + " times!!! You've LOST: " + loseCounter + " times!!!");
            }
            playerSelection = scanny.nextLine().charAt(0);
        }
    }
}

Basically, you need to put the logic into a loop which is what this line does: while (playerSelection != 'q')

After the program gets the input and does the R,P,S check, call scanner again for the user’s next intention at the last line before the end of the while loop.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top