// Arup Guha
// 2/11/2017
// Example of creating a class.

import java.util.*;

public class gumball {

	// My possible gumball colors.
	final public static String[] COLORS = {"red", "green", "blue", "yellow", "purple"};

	// Instance variables of my gumball object.
	private ArrayList<String> list;
	private double cash;

	// Constructor - creates a gumball with size # of gumballs.
	public gumball(int size) {
		
		// Put size # of random gumballs into the machine (list).
		Random r = new Random();
		list = new ArrayList<String>();
		for (int i=0; i<size; i++)
			list.add(COLORS[r.nextInt(COLORS.length)]);
			
		// Machine starts with no money.
		cash = 0;
	}

	public String dispense() {

		// Nothing left.
		if (list.size() == 0) return null;

		// Just takes the item at the front of the list and dispenses it (we get 25 cents!)
		String item = list.remove(0);
		cash += .25;		// cash = cash + .25
		return item;
	}

	public void restock(int[] newitems) {
		
		// Bit of error checking.
		if (newitems.length != COLORS.length) return;

		// Go through each color and add the appropriate number of that color.
		for (int i=0; i<COLORS.length; i++)
			for (int j=0; j<newitems[i]; j++)
				list.add(COLORS[i]);
		Collections.shuffle(list);
	}

	public static void main(String[] args) {

		gumball machine = new gumball(10);

		// Eat all of the gumballs!
		for (int i=0; i<10; i++) {
			String eat = machine.dispense();
			System.out.println("Ate "+eat);
		}

		// Add some and eat some more =)
		int[] add = {3, 5, 2, 8, 2};
		machine.restock(add);
		System.out.println("After restock");
		for (int i=0; i<20; i++) {
			String eat = machine.dispense();
			System.out.println("Ate "+eat);
		}

	}

}