You are on page 1of 2

package lotteryProgram; import java.util.

ArrayList; public class Ball { static ArrayList<Integer> ballNo = new ArrayList<Integer>(); int numbers; Ball(){ int checker; do { checker = (int)(Math.random()*50+1); } while (ballNo.contains(checker)); numbers = checker; ballNo.add(checker);

} }

package lotteryProgram; import java.util.ArrayList; public class Container { ArrayList<Ball> container; Container(){ container = new ArrayList<Ball>(); //creating the container for (int i=0; i<12; i++) { container.add(new Ball()); //adding balls to the container via for loop } } }

package lotteryProgram; public class Popper { /** * @param args */ public static void main(String[] args) { Container lol = new Container(); int[] winners = new int[6]; System.out.println("the 12 selected balls are: "); for (int i=0;i<12;i++)

{ System.out.print(lol.container.get(i).numbers+","); } System.out.println("\nThe winning numbers are: "); for (int i=0;i<6;i++) { int temp = (int)(Math.random()*lol.container.size()); winners[i] = lol.container.get(temp).numbers; lol.container.remove(temp); System.out.print(winners[i]+","); }

} }