import java.util.ArrayList;
import java.util.Iterator;

/**
 * An example for using Junit
 */
 
public class Bag4fruit {

	private ArrayList _fruits;

	/**
	 * Constructs a <code>Bag4fruit</code> instance.
	 */
	public Bag4fruit() {
		_fruits = new ArrayList();
	}

	/**
	 * Returns the balance.
	 *
	 * @return Balance.
	 */
	public double getBalance() {
		Iterator i = _fruits.iterator();
		double balance = 0.00;
		while (i.hasNext()) {
			Fruit p = (Fruit)i.next();
			balance = balance + p.getPrice();
		}

		return balance;
	}
	
	/**
	 * Adds the specified product.
	 *
	 * @param f Fruit.
	 */
	public void addFruit(Fruit f) {
		_fruits.add(f);
	}

	/**
	 * Removes the specified product.
	 *
	 * @param f Fruit.
	 */
	public void removeFruit(Fruit f) {
		if (!_fruits.remove(f)) {
			System.out.println("Error in removing");
		}
	}

	/**
	 * Returns the number of fruits in the bag.
	 *
	 * @return Fruits count.
	 */
	public int getFruitCount() {
		return _fruits.size();
	}
	
	/**
	 * Empties the cart.
	 */
	public void empty() {
		_fruits = new ArrayList();
	}

	/**
	 * Indicates whether the bag is empty.
	 *
	 * @return <code>true</code> if the bag is empty;
	 *         <code>false</code> otherwise.
	 */
	public boolean isEmpty() {
		return (_fruits.size() == 0);
	}
}