Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

assistance with method in guessing game

807591Apr 30 2008 — edited May 5 2008
Hey guys I developed a method called processGuess which gets an array of ints passed to its parameter, adds the guess and its results to the guessHistory string and then returns a boolean depending if the guess is a winner or not. heres my algorithm:
 public boolean processGuess(int[] guess)
    {
        for(int i=0;i<boardSize;i++)
        {
            guessHistory+=guess[i]+"  ";
        }
        
        guessHistory+="\t"+getGuessResults(guess)+"\n";
       
        String mysteryNums=getMysteryNumbers();
        
        String theResults=getGuessResults(guess);
        
        boolean haveWinner=false;
        
        if(mysteryNums.length()==theResults.length())
        {   
            haveWinner=true;
            for(int i=0;i<theResults.length();i++)
            {
                if(theResults.charAt(i)!='X')
                {
                   haveWinner=false; 
                }
            }
        }
       
        return haveWinner;
        
    } // end method processGuess
the logic is if the guess results is the same length as the mystery numbers haveWinner is true and provided that all characters in the results are 'X" (a correct number in the correct position) then haveWinner remains true but the first character that is a # haveWinner is set to false. This seems logical but it isn't declaring a winner when the correct numbers are guessed.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2008
Added on Apr 30 2008
20 comments
187 views