Results 1 to 2 of 2
Thread: help me make a word guesser
- 03-15-2010, 02:48 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 14
- Rep Power
- 0
help me make a word guesser
hi
in this code the computer will pick a random word from the list and try to guess it (the computer is guessing it).
well in this code if the computer doesn't guess the word it will stay in an infinit loop until the computer guesses the word
can anyone help me make a code to make the computer guess the word letter by letter
I'm using bluej software to write the java code:
this is my main code:
Java Code:import java.util.*; // bluej is actually a bad name of a class because it should start with capital letter. public class WordGuesser { public static void main(String[]args) { System.out.println("start"); ArrayList words = new ArrayList(); words.add("hello"); words.add("car"); words.add("dog"); words.add("plane"); words.add("plant"); words.add("help"); words.add("job"); words.add("java"); words.add("blue"); words.add("bathroom"); Die die = new Die(words.size()); System.out.println(die); boolean isCorrect = false; while(!isCorrect) { System.out.println("What word am I thinking of?"); String guess = ""; // read in guess using System.in isCorrect = die.equals(guess); if(!isCorrect) { System.out.println("Sorry that wasn't correct."); } else { System.out.println("That's correct. I was thinking of " + die); } } System.out.println("finish"); } }
this is the die code which it uses to pick a random word :
Java Code:public class Die { private int noFaces; private int faceValue; /** * @param faces the number of faces on the new die */ public Die( int faces ) { if (faces > 1) { noFaces = faces; } else { noFaces = 2; } // if // initialise faceValue as a default faceValue = roll(); } // constructor /** * @return the value the current face is to */ public int getFaceValue() // this method may not be used in the completed game { System.out.println("Face has value: " + faceValue); return faceValue; } /** * @param newFaceValue the value to set the face to */ public void setFaceValue(int newFaceValue) { if (newFaceValue > noFaces) { faceValue = noFaces; } else { faceValue = newFaceValue; } System.out.println("Face set to value: " + faceValue); } /** * @return the value a newly-selected face is set to */ public int roll() { faceValue = (int) (Math.random() * noFaces) + 1; // System.out.println("New face set to value: " + faceValue); return faceValue; } }
and this is some code that was given to me and I was asked to use but I didn't know how to use it so if there is a way to use it please tell me how:
Java Code:import java.util.Scanner; /** * InputReader reads text input from the text terminal. */ public class InputReader { private Scanner reader; /** * Create a new InputReader that reads from the terminal */ public InputReader() { reader = new Scanner(System.in); } public String getString() { String input = reader.nextLine(); return input; } public int getInt() { int input = reader.nextInt(); reader.nextLine(); return input; } }
- 03-15-2010, 02:49 PM #2
Member
- Join Date
- Mar 2010
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
positining of word
By vividcooper in forum New To JavaReplies: 5Last Post: 01-16-2010, 10:21 PM -
WORD Translation HELP PLZ :(
By sammypants in forum New To JavaReplies: 2Last Post: 11-24-2009, 01:46 PM -
Word
By right2001 in forum New To JavaReplies: 2Last Post: 04-07-2009, 03:25 AM -
Word OLE
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:33 PM -
How to make online jsp forms from Microsoft word forms in java
By jiten.mistry in forum Advanced JavaReplies: 2Last Post: 04-28-2008, 10:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks