wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Trouble with lottery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble with lottery" Watch "Trouble with lottery" New topic
Author

Trouble with lottery

Cutter Jones
Greenhorn

Joined: Sep 05, 2009
Posts: 2
Good Morning
Im a very new Java enthusiast,

I'm try to find some help with this please

User inputs 3 numbers
for correct matches then
1 correct wins $10.00
2 correct wins $100.00
3 correct wins $1000.00

if user inputs 123
and random generator comes back 111 he/she should only win once

if user inputs 120 should win twice...etc...etc...

I have if all three numbers match, but seem to have trouble with the other parts...

What I have so far
CODE:

import java.util.*;
import javax.swing.JOptionPane;

public class Lottery

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

int allRanNumbers;



allRanNumbers = (int)(Math.random() * 1000);
System.out.println(allRanNumbers);

String guessString;
int guess;

guessString = JOptionPane.showInputDialog(null,
"Please enter 3 digits from 0-9", "Lottery Numbers",
JOptionPane.QUESTION_MESSAGE);
guess = Integer.parseInt(guessString);

if (guess == allRanNumbers)

System.out.println("You matched two: you win $1000.00");


CODE:

any help would be greatly appreciated

Thank you

CutterJones
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18916
    
  40

any help would be greatly appreciated


It would help if you tell us what problem you are running into. And what are you confused with.

Telling us the assignment, and the code that you did so far, isn't enough for us to give you a hint in the right direction.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Cutter Jones
Greenhorn

Joined: Sep 05, 2009
Posts: 2
Sorry...
The assignment is create a lottery
where the user inputs 3 numbers and wins $$ based on the amount of numbers he or she matches.

the user cannot win with matching two numbers
example if 123 is the number randomly generated and the user inputs 121, he /she cannot win twice with the numer 1
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Welcome to JavaRanch
How do you think you can check whether you have the "1" matching twice? Or can you stop checking when you have found the first "1"?
Cutter Jones
Greenhorn

Joined: Sep 05, 2009
Posts: 2
Thanks Campbell Richie...

I tries using three seperate "random" instances but couldn't make heads or tails of my if statements, and scraped the idea.

Do you think that is the way to go?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with lottery