// Arup Guha
// 5/25/2010
// Solution AP Computer Science Free Response Problem #1

import java.util.*;

public class MasterOrder {
	
	private List<CookieOrder> orders;
	
	public MasterOrder() {
		orders = new ArrayList<CookieOrder>();
	}
	
	public void addOrder(CookieOrder theOrder) {
		orders.add(theOrder);
	}
	
	// Solution to Part A.
	public int getTotalBoxes() {
		
		// Just go through each Order and add in the number of
		// boxes.
		int sum = 0;
		for (CookieOrder c : orders)
			sum += c.getNumBoxes();
			
		return sum;
	}
	
	// Solution to Part B.
	public int removeVariety(String cookieVar) {
		
		int sum = 0;
		
		// Go through each order.
		for (int i=0; i<orders.size(); i++) {
			
			// If we find the ones we need to remove, add to
			// our counter and THEN remove.
			if (orders.get(i).getVariety().equals(cookieVar)) {
				sum += orders.get(i).getNumBoxes();
				orders.remove(i);
			}
		}
		
		return sum;
	}
	
	// For testing purposes.
	public String toString() {
		String answer = "";
		for (CookieOrder c : orders)
			answer += c+"\n";
		return answer;
	}
	
	public static void main(String[] args) {
		
		// Sample code segment from test.
		MasterOrder goodies = new MasterOrder();
		goodies.addOrder(new CookieOrder("Chocolate Chip", 1));
		goodies.addOrder(new CookieOrder("Shortbread", 5));
		goodies.addOrder(new CookieOrder("Macaroon", 2));
		goodies.addOrder(new CookieOrder("Chocolate Chip", 3));
		
		System.out.println(goodies);
		int removed = goodies.removeVariety("Chocolate Chip");
		
		System.out.println("After removing " + removed+ " chocolate chip we have: ");
		System.out.println(goodies);
	}
}