1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need some java help please

Discussion in 'Java' started by ELHEK, May 28, 2006.

  1. ELHEK

    ELHEK New Member

    Joined:
    May 28, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey ppl im tring to run this code, it compiles but doesnt exucute properly, the loop Statement has an error. please any one help

    Code:
    public class lele
    {
       private String word;
       private char letterguessed;
       private int numberOfMistakes;
       private char wronglyGuessLetters;
       private char[] lettersAvalible = new char[26];
    
    
       public lele(String word, char letterguessed)
    
       {
          this.letterguessed = letterguessed;
          this.word = word;
          numberOfMistakes = 0;
          wronglyGuessLetters = (char)0;
          for( int j = 0; j < lettersAvalible.length; j++ )
          {
             lettersAvalible[j] = (char)('A' + j);
          }
       }
    
       public void displayWord(char[] hiddenWord)
    
       {
          for ( int i = 0; i < hiddenWord.length; i++)
          {
             if ( letterguessed != word.charAt(i) )
             {
                hiddenWord[i] = '*';
    
             }
             else
             {
                hiddenWord[i] = (char)letterguessed;
    
             }
             System.out.print( hiddenWord[i] );
          }
       }
    
       public void checkGuess(int count)
    
                            
       {
          for ( int i = 0; i < word.length(); i++)
          {
    
             if ( letterguessed != word.charAt(i) )
             {
                count++;
             }
    
             if ( count == word.length() )
             {
                numberOfMistakes++;
                wronglyGuessLetters += (char)letterguessed;
                System.out.println("Number of Mistakes: " + numberOfMistakes + "\nWrongly letters: " + wronglyGuessLetters);
             }
    
          }
          if( numberOfMistakes == 9 )
          {
             System.out.println("\nGAME OVER");
          }
    
    
       }
    
       public void lettersLeft()
    
       {
          System.out.println("\nLetters Availble: ");
          for ( int i = 0; i < lettersAvalible.length; i++ )
          {
             if ( letterguessed == lettersAvalible[i] )
             {
                lettersAvalible[i] = (char)' ';
             }
    
          System.out.print( lettersAvalible[i] );
          }
    
       }
    
    }
    
    and then.....

    Code:
    import java.util.*;
    public class lwlw
    {
       public static void main(String[] args)
       {
          System.out.println("Please insert a word to be guessed");
          Scanner keyboard = new Scanner(System.in);
          String word = keyboard.nextLine();
          System.out.println("please guess a letter");
          char letterguessed = keyboard.next().charAt(0);
          int counter = 0;
          char[] hiddenWord = new char[word.length()];
          lele test = new lele(word, letterguessed);
          do
          {
             test.displayWord(hiddenWord);
             test.checkGuess(0);
             test.lettersLeft();
             System.out.println("\nGuess another letter");
             letterguessed = keyboard.nextLine().charAt(0);
             counter++;
             }while( counter != word.length() );
          System.out.print("\nGAME OVER, thanks for using!");
    
    
       }
    }
    
    thanks for any replys!
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Which loop causing you the problem.
     

Share This Page