Hi Everyone,
I am new to java and the assignments are are fairly simple for someone more experienced. I am currently having trouble with accumulating my variables for tallying the number of guesses of each color in the place that I need them to. I am also having trouble with my random number generator. I know that it is only selecting one 1 random number then using that 1 number through all 10 iterations of the loop when I need it to generate a new number for each guess. The actual specs in the books words is contained within the jpg. Thank you for any advice.
20130327_111310.jpg
import java.util.Random; import java.util.Scanner; public class ESPgame { String colorInput, computerColor; int computerNum, correct, incorrect; int redGuess, greenGuess, blueGuess, orangeGuess, yellowGuess; Scanner keyboard = new Scanner(System.in); Random rand = new Random(); public static void main(String[] args) { ESPgame newGame = new ESPgame(); newGame.welcomeGamer(); newGame.inputColor(); newGame.computerColor(); newGame.colorGuess(); newGame.reportGame(); System.exit(0); } public void welcomeGamer(){ System.out.println("Welcome to the ESP Game!"+ "\nTry to guess the same color as the computer. There are 10 attempts."); } public void inputColor(){ System.out.println("Please enter your choice of color: "+ "\nRed" + "\nGreen" + "\nBlue" + "\nOrange" + "\nYellow"); colorInput = keyboard.nextLine(); } public void computerColor(){ computerNum = rand.nextInt(4); if (computerNum == 0){ computerColor = "red"; } else if(computerNum == 1){ computerColor = "green"; } else if(computerNum == 2){ computerColor = "blue"; } else if(computerNum == 3){ computerColor = "orange"; } else if(computerNum == 4){ computerColor = "yellow"; } } public void colorGuess() { correct = 0; incorrect = 0; for(int i = 0; i < 10; i++){ if(colorInput.equalsIgnoreCase(computerColor)){ System.out.println("Lucky! You guessed the same color as the computer."); correct ++; } else { System.out.println("Sorry! Guess again."); incorrect ++; } colorTally(); inputColor(); } keyboard.close(); } // end method public void colorTally() { redGuess = 0; greenGuess = 0; blueGuess = 0; orangeGuess = 0; yellowGuess = 0; if(colorInput.equalsIgnoreCase("red")){ redGuess ++; } else if(colorInput.equalsIgnoreCase("green")){ greenGuess ++; } else if(colorInput.equalsIgnoreCase("blue")){ blueGuess ++; } else if(colorInput.equalsIgnoreCase("orange")){ orangeGuess ++; } else if(colorInput.equalsIgnoreCase("yellow")){ yellowGuess ++; } else { System.out.println("Invalid Color"); } } // end method public void reportGame(){ System.out.println("The Results of the game are in!"+ "\nPlayer 1:"+ "\nCorrect guesses: " + correct + "\nIncorrect guesses: " + incorrect + "\nRed guesses: " + redGuess + "\nGreen guesses: " + greenGuess + "\nBlue guesses: " + blueGuess + "\nOrange guesses: " + orangeGuess + "\nYellow guesses: " + yellowGuess ); } // end method } // end class