File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble with lottery

 
Cutter Jones
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic