1. Member Join Date
Feb 2011
Posts
6
Rep Power
0

## lottery HELP IMMEDIATELY

\**
* We want to simulate pulling lottery numbers
* Our lottery has balls with the numbers 1 to 30
* We want to draw seven at a time
* We want to run the simulation 1000 times
* We will load a ArraySet with the numbers 1-30 and
* randomly draw seven
*
* We will do two tests
* 1. Keep an array of how many times each number is drawn
* 2. Get an overall average of the value of the ball drawn
*/
public class Lottery {

public static void main(String[] args) {
final int NUMBALLS=30;
final int NUMRUNS = 1000;
double average = 0;
int[] count = new int[NUMBALLS+1];

for (int i=0;i<NUMRUNS;i++)
{
average = oneTest(bag,7, count, average, i);
}

print(average, count);

}

{
// create a LinkedBag that has the numbers 1-30 in it
ArraySet lb = new ArraySet();
return lb;

}

public static double oneTest(ArraySet bag, int numBalls, int[] numDraws, double ave, int numRuns) {
// remove a random ball
// increment the array in the location of the ball's numeric value (ie if the ball is a 7, increment location 7

ArraySet<Integer> lb = new ArraySet<Integer>();
for(int i = 1; i <= 7; ++i)
Random ran = new Random();
for(int i = 0; i < 7; ++i)
{
int Value = ran.nextInt(lb.size());
int num = lb.remove(Value);
}
// also keep a running total
int count = 0;

numRuns += numBalls;
count++;

// do this for all numBalls balls

// recalculate the average so it is an overall average for all trials

// return the average

// HINT: the way to turn a Integer into an int is with .intValue()

}
public static void print(double ave, int[] numDraws)
{
System.out.println("The average value on the balls with multiple random pulls is " + (int)ave);
System.out.println("This value should be close to " + (numDraws.length-1)/2);
System.out.println("Each ball was pulled as below");
for (int i=0;i<numDraws.length-1;i++)
{
if (i==0 || i==5) System.out.print(" ");
System.out.print(i+1 + ": " + numDraws[i+1] + " ");
if (i<8) System.out.print(" ");
if (i%5==4)
System.out.println();
}
}

}

THANK YOU
Last edited by kayln; 02-21-2011 at 04:36 AM.  Reply With Quote

help soon as possible 