Results 1 to 3 of 3
- 03-16-2012, 03:52 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Multiple issues with my 1-6 guessing game.
Hi all,
First I want to thank all of you for your help. Secondly, I stink at object-oriented programming. I think it has something to do with how I logically think. Lastly, I read through as much forums and did as much google(ing) as I possibly could.
The program is a guessing game that is from 1 -6. I have the opening message working. The userChoice method works also, but I am trying to add a counter because I know the actual value of "1" is 0.
I think that it goes somewhere after the if statement or that I may have to change it to a do while loop.Java Code:public static void userChoice() //This method allows the user to click a number in the following showOptionDialog { int getChoice;// this stores the users choice into an integer variable int mouseClick = JOptionPane.QUESTION_MESSAGE; // this stores the click into a variable String[] options = { "1", "2", "3", "4", "5", "6", "Exit"}; // END STRING OPTIONS getChoice = JOptionPane.showOptionDialog (null, "Choose a Figure", "Title", 0, mouseClick, null, options, options[2]); if (getChoice >= 0) System.out.println ("You clicked " + options[getChoice]); // END IF else { System.out.println ("You closed the box."); } // END ELSE randomNum(); //this moves the program to the next method } // END METHOD USERCHOICE
Another issue I am having is comparing the data gathered from the userChoice method to the randomNum / getRand methods.
My apologies if you cannot understand what I am trying to get accomplished. I am very well spoken but not in Java programming.Java Code:public static void randomNum() //random number generator method { // put in its own method when done int counter = 1; int getNum; do { getNum = getRand(); counter++; // same as ctr = ctr + 1; } while (counter <= 6); System.out.println ("The roll was " + getNum); // use do while loop for fun }// main public static int getRand() // returns an int value via the return statement { Random generator = new Random(); // declare a new Instance of type Random int rNum = generator.nextInt(6) + 1; // generator.nextInt(6) creates numbers from 0 to 5; thus the reason to add 1 return rNum; // return value
- 03-16-2012, 06:22 AM #2
Member
- Join Date
- Feb 2012
- Location
- Phoenix, AZ
- Posts
- 26
- Rep Power
- 0
Re: Multiple issues with my 1-6 guessing game.
Have you considered passing the getChoice variable to the randomNum method? Then, you can just say
This could be placed in the randomNum() method.Java Code:if( getChoice == getNum) System.out.println("match found"); else System.out.println("match not found");
- 03-16-2012, 05:52 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Re: Multiple issues with my 1-6 guessing game.
A copy of the value in x, which is 5, is passed into the doStuff() method.Java Code:int x = 5; doStuff(x); // pass a COPY of x (the value 5) to the doStuff method The doStuff method looks like this: void doStuff(int y) { // use y in some way }
I am trying to do this except "x" equals "getChoice" and there is no equal sign. No value assigned to getChoice. I want to pass a copy of getChoice to the randomNum(); method like you said.
I have also tried assigning the getChoice variable to itself to no avail.Last edited by intEquals_EJ; 03-16-2012 at 06:23 PM.
Similar Threads
-
guessing game
By MrM in forum New To JavaReplies: 1Last Post: 02-02-2011, 07:51 PM -
Need help in Guessing Game
By rose in forum Java GamingReplies: 4Last Post: 10-27-2010, 10:43 PM -
Guessing Game
By rose in forum Java GamingReplies: 4Last Post: 10-27-2010, 08:00 PM -
guessing game help
By yasmin k in forum AWT / SwingReplies: 4Last Post: 10-31-2009, 05:37 PM -
guessing game using GUI
By yasmin k in forum New To JavaReplies: 1Last Post: 10-26-2009, 12:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks