Results 1 to 1 of 1

Thread: lottery

  1. #1
    kayln is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Question 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 YOU
    Last edited by kayln; 02-21-2011 at 04:36 AM.

Similar Threads

  1. Lottery help, looping problem
    By hadoken5 in forum New To Java
    Replies: 2
    Last Post: 10-31-2010, 07:48 PM
  2. Lottery Application
    By notnumber6 in forum New To Java
    Replies: 3
    Last Post: 11-03-2007, 12:42 PM

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
  •