Selvart
Selvart

Reputation: 19

'.class' error cannot be identified?

I am making a hangman game, this is the part of my code where all the problems are:

    //play method
    private void play() throws IOException
    {
        guess(alphabet);

        usedLetters(letterUsed);

        do{
            centreln("You have already guessed this " + alphabet + " and the others listed above.");
            guess();
        } while (letterUsed == true);//will keep asking until letter was not used

        if (letterUsed == false)
        {
            life--;
            underWord();
        } //only if the letter was not used, it will be checked for in the current word trying to be solved

        if (life == 0)
        {
            checkWord(currentWord[] , checkLetter[]);
        }
    }//End of play method

//------------------------------------------------------------------------------------------------------------------------------

//maskWord method to return the word with all characters not in letters replaced by _'s
private void underWord(char currentWord[] , char checkLetter[]) throws IOException //add parameters what it recieves
{

    for (int i = 0; i<currentWord.length; i++) {
       for (int index = 0; index<checkLetter.length; index++){
            if (used.contains(currentWord.charAt(i)))
            {
                checkLetter[index] =  currentWord.charAt(i);
            }

            else
            {
                checkLetter[index] = '_';
            }
       }
    }
    for (int i = 0; i < checkLetter.length; i++)
    {
        System.out.println(checkLetter[i]);
    }
}//End of maskWord method

//------------------------------------------------------------------------------------------------------------------------------

//guess method to ask for user's guess
private void guess(char used[]) throws IOException//add parameters what it recieves
{
    centreln("Guess a letter in this 5-letter word: ");
    alphabet = kb.readline().charAt[0];
    used[dataSize] = alphabet;
    //adds guess to used letters array

}//End of guess method

//------------------------------------------------------------------------------------------------------------------------------

//usedLetters method to check if user's guess has already been guessed
private boolean usedLetters(char used[]) throws IOException//add parameters what it recieves
{
    boolean letterUsed = false;
    for(int x=0; x<used.length; x++)
    {
        if(alphabet == used[x])
        {
            letterUsed = true;
        }
        else
        {
            letterUsed = false;
        }
     }
     return letterUsed;
    for (int index = 0; index < used.length; index++)
    System.out.println(used[index]);
    //Or could i just do centreln(usedAlphabet)
}//End of usedLetters method

//------------------------------------------------------------------------------------------------------------------------------

//checkWord method to see if the user has got the correct word
private void checkWord() throws IOException
{
    for(int x=0; x<currentWord.length; x++)
    {
        if(checkLetter.equals(currentWord))
        {
            centreln("HUZZAH! You have guessed the word!");
            centreln("You have completed this game of hangman.");
            menu();
        }

        {
            centreln("You have run out of guesses!");
            centreln("The word was:");
                for (int index = 0; index < currentWord.length; index++)
                {
                    System.out.print(currentWord[index]);
                }
            menu();
        }
    }
}//End of checkWord method

}

//------------------------------------------------------------------------------------------------------------------------------

So I come up with this error:

C:\Users\HOME\Documents\twoHangman\src\twoHangman.java:272: error: '.class' expected
            checkWord(currentWord[] , checkLetter[]);
                                    ^
C:\Users\HOME\Documents\twoHangman\src\twoHangman.java:272: error: '.class' expected
            checkWord(currentWord[] , checkLetter[]);
                                                   ^

I am not sure what is wrong...Please help!

Upvotes: 0

Views: 91

Answers (3)

scrappedcola
scrappedcola

Reputation: 10572

You have a method checkWord defined that does not take any arguments, however when you call that method you are passing 2 parameters checkWord(currentWord[] , checkLetter[]); you need to define a method that takes two params. Also when you are calling checkWord(currentWord[], checkLetter[]) it should be checkWord(currentWord, checkLetter)

Edit to answer Question: One way to solve your issue would be to update your definition of checkWord this way:

private void checkWord(String[] currentWord, String[] checkLetter) throws IOException

Upvotes: 0

buc
buc

Reputation: 6358

I think the problem in in your play() method. Instead of

if (life == 0)
{
    checkWord(currentWord[] , checkLetter[]);
}

you should write

if (life == 0)
{
    checkWord(currentWord, checkLetter);
}

to pass the arrays as parameters.

As Kent pointed out, the other error is in your checkWord method. Instead of

private void checkWord() throws IOException

you should write

private void checkWord(char currentWord[], char checkLetter[]) throws IOException

to declare that this method takes two arguments of character array type.

Upvotes: 3

Kent
Kent

Reputation: 195039

in your first code block, the play method, you have this method call:

checkWord(currentWord[] , checkLetter[]);

but take a look the method signature of checkWord():

private void checkWord() throws IOException

where are the parameters?

are your codes compiled?

Upvotes: 1

Related Questions