Sunday, July 12, 2009

Help Please GUI Java Program Random Letter or Number Guessing Game. Based on what the user enteres first.?

I'm trying to write a GUI Java guessing game with the user. The user enters a number between 1-10 OR letters between A-K (uppercase). The user is suppose to have a choice, This program is suppose to generate a random number in the same range OR a letter to compare to the user’s input and declare whether you have matched each other or not.


This is my code but It doesn't work, can someone please show me.


import java.io.*;


import java.util.Random;





public class Guess2{


public static void main (String[]args) throws Exception{


int randomValue;


String ch;


String guessValue1;


int guessValue2;


String c;


BufferedReader BR;


BR= new BufferedReader(new InputStreamReader(System.in));


//for(int i = 0; i %26lt; 10; i++){


while(true){





randomValue = (int)(Math.random() * 10)+1 ;


ch = String("ABCDEFGHIJK").charAt(randomValue...


System.out.println("The random value is "+randomValue);


//}


System.out.print("Please Guess The Value : ");


guessValue1= BR.readLine();


no more space

Help Please GUI Java Program Random Letter or Number Guessing Game. Based on what the user enteres first.?
Your code looks... quite funky. lol





1. Isn't this suppose to be a GUI program?


2. You imported the Random class, yet you aren't using it.


i. If I'm correct, you can specify a range of possible values when using random.


ii. You can then convert the integer, ASCII value to a character or vice versa to do a comparison.





The amount of code required should be minimal.


1. Prompt for input


2. Check that the input falls within 1-10, or A-K


3. Once you know where it falls, randomly pic a value in that range (specify range to random object created from the Random class)


4. Cast randomly selected value to char and compare to input





You don't need to use the Math class.
Reply:LA

survey questions

No comments:

Post a Comment