Results 1 to 8 of 8
Thread: need help with this java code
- 03-16-2010, 01:30 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 14
- Rep Power
- 0
need help with this java code
hi I've done this java code to make the computer guess a random word from the array
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 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"); } }
I need help to make the computer guess the word letter by letter
please help cause I'm not that great on java just started learning it a month ago
- 03-16-2010, 01:33 PM #2
What is Die? What exactly are you having trouble with?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-16-2010, 01:44 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 14
- Rep Power
- 0
Die is a class that makes the computer guess a random word this is it's code
and what I want help with is the game I'm makingJava 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; } }
I'm making a hangman game for the computer
so a random word from the arraylist is chosen and the computer has to guess it
with the code that I've got the computer is guessing them word by word
and I need help making the computer guess them letter by letter and I don't really know how to do it
- 03-16-2010, 02:01 PM #4
Huh?! The computer doesn't guess anything at all. :confused:
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-16-2010, 02:12 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 14
- Rep Power
- 0
ohhhh I'm mixed up can you help me fix it cause I don't really know what I'm doing
- 03-16-2010, 02:20 PM #6
Same here. I have no idea what you are trying to do. What you have said before isn't reflected anywhere in your code.
I suggest you start from scratch and do it step by step with lots of debug outputs.
Nobody here will fix anything for you. You have to do it yourself. We'll be glad to answer specific questions and give advice.Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-16-2010, 09:05 PM #7
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
I think what you want to do is this: instead of
haveJava Code:isCorrect = die.equals(guess)
Java Code:String wordToTarget = (String)words.get (die.getFaceValue ()); isCorrect = wordToTarget.equals (word);
- 03-17-2010, 01:08 PM #8
Member
- Join Date
- Mar 2010
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
java code
By noor in forum New To JavaReplies: 2Last Post: 01-01-2010, 02:00 PM -
Convert java code to midlet code
By coldvoice05 in forum New To JavaReplies: 1Last Post: 08-12-2009, 11:14 AM -
Convert java code to midlet code
By coldvoice05 in forum Advanced JavaReplies: 1Last Post: 08-09-2009, 01:21 PM -
Java Code
By g.ganiraju in forum New To JavaReplies: 2Last Post: 10-20-2008, 02:18 PM -
Need a java code
By vissu007 in forum New To JavaReplies: 1Last Post: 07-11-2007, 10:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks