Results 1 to 2 of 2
  1. #1
    grcarr77 is offline Member
    Join Date
    Oct 2011
    Posts
    8
    Rep Power
    0

    Default Lottery Java Program please help

    When I run the program below it matches all digits in any order, but when I test it to recognize one digit and pay out 1,000 it says pay out 3,000 on certain three digits for example 900 entered.

    Please help, trying to correct this code, been working on it for days and cant understand where I am going wrong



    Java Code:
    package lottery.lottery;
    
    import java.util.Scanner;
    
    public class Lottery{
         public static void main(String[ ] args)  {
                 // generate a lottery
              int lottery = (int)(Math.random() *1000);
    
              // Prompt the user to enter a guess
              Scanner input = new Scanner(System.in);
              System.out.print("Enter your lottery pick (three Digits):");
              int guess = input.nextInt();
    
              //Get digits from lottery
              int  lotteryDigit1 = lottery / 100;
              int  lotteryDigit2 = ((lottery / 10) % 10);
              int  lotteryDigit3 = lottery % 10;
              //get digits from guess
              int  guessDigit1 = guess / 100;
              int  guessDigit2 = ((lottery / 10) % 10);
              int  guessDigit3 = guess % 10;
    
              System.out.println("The lottery number is " + lottery);
    
              // Check the guess
              if (guess == lottery)
    
                 System.out.println ("Exact match: you win $10,000");
    
             else if (guessDigit2 == lotteryDigit1
                   || guessDigit1 == lotteryDigit2
                   || guessDigit3 == lotteryDigit2
                   || guessDigit2 == lotteryDigit3
                   || guessDigit3 == lotteryDigit1
                   || guessDigit1 == lotteryDigit3)
                  System.out.println ("Match all digits: you win $3,000");
             else if (guessDigit1 == lotteryDigit1
                   && guessDigit1 == lotteryDigit2
                   && guessDigit1 == lotteryDigit3
                   && guessDigit2 == lotteryDigit1
                   && guessDigit2 == lotteryDigit2
                   && guessDigit2 == lotteryDigit3
                   && guessDigit3 == lotteryDigit1
                   && guessDigit3 == lotteryDigit2
                   && guessDigit3 == lotteryDigit3)
                   System.out.println ("Match one digit: you win $1,000");
               else
                   System.out.println("Sorry, no match");
             }
    }
    Moderator Edit: code tags added
    Last edited by Fubarable; 10-16-2011 at 07:10 PM. Reason: code tags added

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: Lottery Java Program please help

    For one thing, you don't calculate your guessDigit2 correctly ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. to generate random lottery no
    By fakepics500 in forum New To Java
    Replies: 19
    Last Post: 07-08-2011, 09:14 AM
  2. Random Lottery Numbers
    By ComicStix in forum New To Java
    Replies: 2
    Last Post: 04-29-2011, 06:18 AM
  3. lottery
    By kayln in forum Eclipse
    Replies: 0
    Last Post: 02-20-2011, 09:28 PM
  4. Lottery help, looping problem
    By hadoken5 in forum New To Java
    Replies: 2
    Last Post: 10-31-2010, 06:48 PM
  5. Lottery Application
    By notnumber6 in forum New To Java
    Replies: 3
    Last Post: 11-03-2007, 11:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •