Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 28th, 2006, 5:41 AM   #1
ELHEK
Newbie
 
Join Date: May 2006
Posts: 9
Rep Power: 0 ELHEK is on a distinguished road
2nd shot please help

Hey ppl im tring to run this code, it compiles but doesnt exucute properly, the loop Statement has an error. please any one help

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.....

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!
ELHEK is offline   Reply With Quote
Old May 28th, 2006, 7:18 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by ELHEK
Hey ppl im tring to run this code, it compiles but doesnt exucute properly, the loop Statement has an error. please any one help
It rather helps to say what the error actually was. Uncaught Java exceptions output a lot of debugging information, including the current thread stack upon receiving the exception. Without this information, diagnosing the problem is far more difficult.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:32 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC