Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Trouble with lottery

 
Greenhorn
Posts: 2
  • 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
 
author
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • 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
  • 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
 
Marshal
Posts: 69784
277
  • 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
  • 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?
 
Arthur, where are your pants? Check under this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic