File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Help with Random Numbers plus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with Random Numbers plus" Watch "Help with Random Numbers plus" New topic

Help with Random Numbers plus

Cutter Jones

Joined: Sep 05, 2009
Posts: 2
Hi everyone.

I'm am new....I am stuck...please help

I'm trying to an assignment, but can't seem to wrap my head around it for some reason.

The assignment is:
-Create a lottery game application.
-Generate three random numbers from 0-9
-Allow the user to guess three numbers.
-Compare each of the users guesses to the three random numbers and
display a message that includes the users guesses and the randomly generated numbers and the amount of $$ won.
-The applications should accomadate repeating numbers.
(ie. the user guesses 1,2,3 and 1,1,1 comes up..he/she should only get credit for the one "1")

I've been going back and forth with different thoughts on how to proceed, and build on what I have.(if possible).

I'm coming here in hopes there is someone, who can guide me in the right direction.
This is where I am so far.


Thank you in advance

marc weber

Joined: Aug 31, 2004
Posts: 11343

I would write this as a command line application first, without worrying about the GUI components. Once you have the logic working (your "model"), then you can connect it to a GUI (your "view").

As for the logical model, you already have the problem fairly well defined in English. I would suggest writing each of these "tasks" as a separate Java method. For example, you might write a method generateRandomNumbers(), or getUserInput(), or displayResults()...

I think you'll find it helpful breaking the assignment down into parts like this. Try that, and see how it goes.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
David Newton

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags. Unformatted code/config/etc. is difficult to read. You can edit your post to include them using the button or re-post the question with proper formatting.
A Mann

Joined: Sep 10, 2009
Posts: 0
I agree with Marc - write a command line application first, and break the task down into manageable chunks (or 'methods').

For overall structure you could maybe try something like this.
(I'm a noob too when it comes to Java, so this is far from perfect, but hopefully helps a little)

Obviously come back and ask again if you get stuck on any of those methods, or anything in this is unclear.

Good Luck
Cutter Jones

Joined: Sep 05, 2009
Posts: 2
Thank you...

Unfortuanatly, we haven't learned "array" yet...I could probably firgure it out, but I don't think that would go over well with my teacher.

I guess my first problem is how do I compare a user input of one 3 digit number to the random 3 one digit numbers...?

There should be a logical way to do least one that a noob like me can understand.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

One solution could be, to match the input from a command line app one digit at a time - like this one:

Regards, Rene Larsen
Dropbox Invite
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
If anybody wishes to continue discussion about deleting text, please go to a duplicate of this thread here. The posts about deleting text will be removed from this copy of the thread.
I agree. Here's the link:
subject: Help with Random Numbers plus
It's not a secret anymore!