Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Trouble with lottery

Cutter Jones
Greenhorn
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
Marshal
Posts: 21730
85
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

Cutter Jones
Greenhorn
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
Posts: 50687
83
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
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?