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...

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

JOptionPane.showMessageDialog(null, "Your Lucky Numbers arrrrre....\n*drumroll*\n\n"

+ "Ticket 1:\n" + Arrays.toString(luckyNumbers) + " Golden Number:" + goldenNumber,

"WELCOME TO THE LOTTERY!",

JOptionPane.INFORMATION_MESSAGE);

}

}

thanks for any help you can give

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

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

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

Re: Need Help with my ticket Program