I'm attempting to use this new method in 1.5.0 for a Hangman program for my programming class
This is the input I'm attempting to get from the user
And this is the error I'm getting from the compiler
Basically, I'm trying to take a char input, and put into a CharSequence, and use the guessThis.contains(z) to tell me if the word contains the letter they input. Then I was going to use the .replaceAll method to replace the ******** with the proper letter. I've got my random word generator working (using a string array and random number generator), and once I get this working, I'll have the program done. And no JOptionPane.
Yes, I know there are more "basic" ways to write this program, but I'm trying to use something new in the 1.5.0 release. But I appreciate anyone who happens to know how to do this, or can point me in the right direction.
Code:
public static boolean compareTo(CharSequence z)
{
return(guessThis.contains(z));
}//end of compareTo
This is the input I'm attempting to get from the user
Code:
public static void playGame() throws Exception
{
System.out.println(hiddenWord);
System.out.print("What is your guess? ");
answer2 = (char)System.in.read();
System.in.read();System.in.read(); //Absorbs Enter Key
CharSequence answer = new CharSequence(answer2);
compareTo(answer);
}//end of PlayGame
And this is the error I'm getting from the compiler
Code:
87: java.lang.CharSequence is abstract; cannot be instantiated
CharSequence answer = new CharSequence(answer2);
^
1 error
Basically, I'm trying to take a char input, and put into a CharSequence, and use the guessThis.contains(z) to tell me if the word contains the letter they input. Then I was going to use the .replaceAll method to replace the ******** with the proper letter. I've got my random word generator working (using a string array and random number generator), and once I get this working, I'll have the program done. And no JOptionPane.
Yes, I know there are more "basic" ways to write this program, but I'm trying to use something new in the 1.5.0 release. But I appreciate anyone who happens to know how to do this, or can point me in the right direction.