Any help with this would be appreciated. Basically I need to setup a function that will track both the
getUserChoice/GetCompChoice scores for each of the 10 Games, however lets say out of 8/10 games the user has won 6 so therefore the user cannot come back to win the most games or tie so the game should end before the 10 limit.
Any help on setting up this initial tracker for the display function would be appreciated.
Below is my code in its current state, minus the counter I'm using for all 10 games.
// Create object for reading from the keyboard.
static Scanner input = new Scanner(System.in);
// Class Contastant to simplify comparisons.
static final String ROCK = "Rock";
static final String PAPER = "Paper";
static final String SCISSORS = "Scissors";
public static void main(String[] args) {
// Get choices
String computerChoice = getComputerChoice();
String humanChoice = getHumanChoice();
// Display the choices that were made
System.out.println("Computer Chose: " + computerChoice);
System.out.println("Human Chose: " + humanChoice);
// Computer the winner
String winner = computeWinner(humanChoice, computerChoice);
// Display the winner
System.out.println("The Winner is: " + winner);
}
// Calculate the winner from the computer and human choices.
private static String computeWinner(String humanChoice, String computerChoice) {
String winner;
// A chain of nested if/else statements. Notice that the tie is only
// checked once. (If the choices are the same, it doesn't matter what
// was specifically chosen!)
if (humanChoice.equalsIgnoreCase(computerChoice)) {
winner = "Game is a Tie!";
} else if (humanChoice.equalsIgnoreCase(ROCK)) {
if (computerChoice.equals(SCISSORS)) {
winner = "Human";
} else {
winner = "Computer";
}
} else if (humanChoice.equalsIgnoreCase(PAPER)) {
if (computerChoice.equals(ROCK)) {
winner = "Human";
} else {
winner = "Computer";
}
} else if (humanChoice.equalsIgnoreCase(SCISSORS)) {
if (computerChoice.equals(PAPER)) {
winner = "Human";
} else {
winner = "Computer";
}
} else {
winner = "There are no winners with invalid input!";
}
return winner;
}
// Get the computer's choice
private static String getComputerChoice() {
// Get a random number between 0 and 2
int randomValue = (int) (Math.random() * 3.0);
String computerChoice;
if (randomValue == 0) {
computerChoice = ROCK;
} else if (randomValue == 1) {
computerChoice = PAPER;
} else {
computerChoice = SCISSORS;
}
return computerChoice;
}
// Get the human's choice
private static String getHumanChoice() {
System.out.print("Please enter Rock, Scissor, or Paper: ");
String inString = input.nextLine();
if (inString.equalsIgnoreCase("rock") || inString.equalsIgnoreCase("paper") ||
inString.equalsIgnoreCase("scissor")){
return inString;
}
else{
System.out.print("Invalid entry, ");
return getHumanChoice();
}
}
}