import java.util.ArrayList; import java.util.Random; /** * An IntBag represents a multiset of integers between min and max. * That is, each number between min and max can occur some non-negative * number of times in a particular IntBag. */ public class IntBag { // arrays // lists // dictionaries // sets // tuples private final ArrayList list; private final int min; private final int max; // constructors in java are like __init__ in python public IntBag(int min, int max) { this.list = new ArrayList<>(); this.min = min; this.max = max; } /** * Adds one instance of value to this IntBag. * @param value the value to be added */ public void add(int value) { this.list.add(value); } /** * Returns true when the bag has no instances of any elements * and false otherwise. * @return true iff the bag is empty */ public boolean isEmpty() { return this.list.isEmpty(); } /** * Chooses (but does not remove) a uniformly random element from this * IntBag in proportion to how many elements exist for each number. * @return the element picked from the bag */ public int pick() { Random r = new Random(); //return this.list.get(r.nextInt(min - 1, max)); return 0; } }