# Thread: Need Help with my ticket Program

1. Member
Join Date
May 2013
Posts
2
Rep Power
0

## Need Help with my ticket Program

Alright so I am still kinda new to java

I am working on a lottery program that will ask the user how many tickets they would like (default being five) and each ticket has a random set of numbers plus a jackpot number:

this is the code have so far...
Java Code:
```import javax.swing.JOptionPane;
import java.util.Arrays;

public class LuckyNumbers
{
public static void main(String[] args)
{
// number of lucky numbers
// number of elements for the lucky numbers
final int LUCKY_NUMBERS = 5;
int[] luckyNumbers = new int[LUCKY_NUMBERS];

// generate five random numbers
for (int i = 0; i < luckyNumbers.length; i++)
{
luckyNumbers[i] = (int) (Math.random() * 56) + 1;
}

Arrays.sort(luckyNumbers); // sort the elements

int goldenNumber = (int) (Math.random() * 46) + 1;  // draw the golden number

// print the numbers
+ "Ticket 1:\n" + Arrays.toString(luckyNumbers) + " Golden Number:" + goldenNumber,
"WELCOME TO THE LOTTERY!",
JOptionPane.INFORMATION_MESSAGE);
}
}```
Last edited by Gruff; 05-01-2013 at 09:47 PM. Reason: added [code] ... [/code] tags

2. ## Re: Need Help with my ticket Program

Shouldn't those five numbers all be different? Note that the random number generator can generate the same numbers in a sequence.

kind regards,

Jos

3. Member
Join Date
May 2013
Posts
2
Rep Power
0

## Re: Need Help with my ticket Program

yeah I forgot about that x.x i was having a bit of a problem with that also, due to not knowing how to keep it from generating the same numbers

4. ## Re: Need Help with my ticket Program

The collections utility class has a shuffle( ... ) method; if you have a List (<--- a Collection) that contains the numbers 1 ... 56 you can shuffle it and take the first five numbers from it and the sixth number can be the 'golden number'; if you do it right it'll be just a few lines of code ...

kind regards,

Jos

5. ## Re: Need Help with my ticket Program

#### Posting Permissions

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