Results 1 to 1 of 1
Thread: lottery
- 02-20-2011, 09:28 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 6
- Rep Power
- 0
lottery HELP IMMEDIATELY
:confused:i am stuck with double oneTest(in bold). please help me.
\**
* 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++)
{
ArraySet bag = load(NUMBALLS);
average = oneTest(bag,7, count, average, i);
}
print(average, count);
}
public static ArraySet load(int num)
{
// 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)
lb.add(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();
}
}
}
I APPRACIATE YOUR HELP
THANK YOULast edited by kayln; 02-21-2011 at 03:36 AM.
Similar Threads
-
Lottery help, looping problem
By hadoken5 in forum New To JavaReplies: 2Last Post: 10-31-2010, 06:48 PM -
Lottery Application
By notnumber6 in forum New To JavaReplies: 3Last Post: 11-03-2007, 11:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks