private static String getHumanChoice() {
System.out.print("Please enter Rock, Scissor, or Paper: ");
String inString = input.nextLine();
return inString;
Basically what I need to switch with this function is to add a conditional that if the user doesn't input any of those correct terms, that then a print statement such as.."invalid user input, please pick again" will then prompt them to input either rock, paper , scissors again.
The bulk of my code is setup this way after the user picks his choice so would I need to change anything in here as well?
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;

New Topic/Question
Reply



MultiQuote





|