import java.text.NumberFormat;
/**********************************************************************
 * MarketBasket.java
 *
 * Represents a market basket.
 ********************************************************************/
public class MarketBasket
{
	/** total number of items actually in the basket */
   private int itemCount; 
   /** total cost of all of the items in the basket */
   private double totalCost; 
   /** Items in the basket */
   private Item[] basket; 

   /***************************************************************
    * Creates an empty shopping basket with a capacity of 
    * of 15 items.  
    ***************************************************************/
   public MarketBasket()
   {
         this.itemCount = 0;
			this.totalCost = 0.0;
			basket = new Item[15];      // make me
   }
   /***************************************************************
    * Adds an item to the basket, updating all pertinent totals.   
    ***************************************************************/
   public void addItem(Item anItem)
   {
      // make me
		this.basket[this.itemCount] = anItem;
		itemCount++;
		totalCost = totalCost + anItem.getItemCost();
		 System.out.println (" adding item # " + this.itemCount);
		 System.out.println (" quantity of item is " + anItem.getQuantity());
		 System.out.println (" unit item cost is " + anItem.getPrice());
		 System.out.println (" total item cost is " + anItem.getItemCost());
		 System.out.println (" total cost is " + this.totalCost);   // make me
   }
  

   /***************************************************************
    * Returns a String representation of this shopping basket
    * @return String representation of the basket, with all items
    *          listed.  
    ***************************************************************/
   public String toString()
   {
      NumberFormat fmt; // number format object
      String contents;  // return String

		// format for currency
      fmt = NumberFormat.getCurrencyInstance();
		
		// headers
      contents = "\nMarket Basket\n-------------";
      contents += String.format("\n%-21s%-9s%10s%10s\n", "Item", "Each", "Quantity", "Total");

		// list each item
      for (int i = 0; i < this.itemCount; i++)
         contents += this.basket[i].toString() + "\n";
  
  		// get final cost 
      contents += "\nTotal Cost: " + fmt.format(totalCost);
      contents += "\n";
		
      return contents;
   }
}
