|
-
February 24th, 2011, 08:50 AM
#1
Lottery simulation
heya, Heya I wanted to simulate a lottery in java. I'm no experienced user so have patience with me.
This is what I have done so far;
public class uppfit3 {
public static void main(String[] args)
{
new lottery ( 500 );
}
}
class lottery {
private int[] numbers;
public lottery ( int n )
{
numbers = new int[n];
// Initialize lottery numbers
int i = 0;
while ( i < n ) {
int r = (int)( Math.random() * n );
if ( add ( numbers, i, r ) ) {
++i;
}
}
show_all ( numbers );
}
private boolean add ( int[] list, int size, int val )
{
for ( int i = 0; i < size; i++ ) {
if ( list[i] == val ) {
return false;
}
}
list[size] = val;
return true;
}
private void show_all ( int[] list )
{
for ( int i = 0; i < list.length; i++ ) {
System.out.print ( list[i] + " " );
}
System.out.println();
}
}
The foregoing code randomize 500 numbers, which is the number of tickets that will conclude in the lottery. And it (the code) also prevents 2 numbers to occur twice
I'm looking to have 3 different profit limits; 1000 £ and 100.000 £. I'm not sure whether
a constant winning percentage or one for each profit.
The number of drawn lottery tickets are specified by the user, the outprint should look like this; enter number of entries (**) <-- a number choosed by the user
and then (example);
Lottery numbers
324 - win: 1000 kr
201
The first one of them was randomly a winning ticket.
I'm kind of stuck here, and I would appreciate if someone could put me on the right track, even the slightest help is welcomed.
best regards
Bertil
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|