Results 1 to 3 of 3
  1. #1
    leoshiner is offline Member
    Join Date
    Oct 2010
    Posts
    28
    Rep Power
    0

    Default Lottery Application

    I am trying to write a lottery program which will read in six numbers and then check these numbers from a randomly generated draw but I cannot
    get the numbers to output to my GUI correctly when I press a button to invoke the method I am getting the button I pressed but the other five output panels are coming up as zeros this is the method I have written

    Java Code:
    public void pickButton(int a){
     
     
     int selection[]= new int[6];   
      int counter=0;  
    for (int i = 0; i < 6; i++) {
    selection[counter]=a;
    for (int j = 0; j < i; ++j) {
    
    
    selection[counter] = a;
    
    
    }
    
    
    
    
    }
    
    
    choice1TextField.setText("" + selection[0]);
    choice2TextField.setText("" + selection[1]);
    choice3TextField.setText("" + selection[2]);
    choice4TextField.setText("" + selection[3]);
    choice5TextField.setText("" + selection[4]);
    choice6TextField.setText("" + selection[5]);
    
    
    counter++;
    
    
    }
    if anyone could point me in the direction where I am going wrong I would greatly appreciate it,if you need to see the full program let me know
    Last edited by Eranga; 03-06-2012 at 12:59 PM. Reason: code tags added

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Lottery Application

    Please use [code] tags [/code] when posting code.

    Java Code:
    int selection[]= new int[6];   
    int counter=0;  
    for (int i = 0; i < 6; i++) {
       selection[counter]=a;
       for (int j = 0; j < i; ++j) {
          selection[counter] = a;
       }
    }
    What is this supposed to do?
    Because at the moment (since 'counter' never changes from 0) you are simply setting 'selection[0] = a' 30 odd times (give or take).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: Lottery Application

    You better take one step at a time. Seems your code segment not clear enough to others, including me. First you want to read six numbers, but how? We cannot see a clear way of doing that. Next generate random numbers and finally validate. Later on you can think about the UI stuff. So explain what you have tried in that code and we can comment on it.

    BTW, if you want to know more about how to use code tags, please have a look at my forum signature. You can find a link there.

Similar Threads

  1. Lottery Java Program please help
    By grcarr77 in forum New To Java
    Replies: 1
    Last Post: 10-16-2011, 07:20 PM
  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
  •