Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Lottery program

807606Mar 19 2007 — edited Mar 20 2007
Okay: heres the question::

Create a lottery game application. Use the Math.random() method to generate three random numbers, each between 0 and 9. Allow the user to guess 3 numbers. Compare each of the user's guesses to the three random numbers. Display how many matched, and how much the user has won.

Any one matching : $10
Two matching: $100
Three matching, not in order: $1000
Three matching, in exact order: $1,000,000
No matches: $0

I just can't wrap my head around how to go about this, its part of a chapter revolving around loops (mainly if loops) and using switch cases. This is the code i have so far, which isn't much.

import java.util.Scanner;

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

Scanner sc = new Scanner(System.in);

int ranNum1;
int ranNum2;
int ranNum2;
int guess1;
int guess2;
int guess3;

ranNum1 = (int)Math.floor(Math.random() * 10);
ranNum2 = (int)Math.floor(Math.random() * 10);
ranNum3 = (int)Math.floor(Math.random() * 10);

System.out.println("Enter your first number: ");
guess1 = sc.nextInt();
System.out.println("Enter your second number: ");
guess2 = sc.nextInt();
System.out.println("Enter your third number: ");
guess3 = sc.nextInt();

Any help would be appreciated, thankyou.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2007
Added on Mar 19 2007
23 comments
978 views