UNB/ CS/ David Bremner/ teaching/ java/ InvoiceTest.java
import java.util.Vector;

public class InvoiceTest
{  public static void main(String[] args)
   {  Customer sam 
         = new Customer("Sam's Small Appliances",
            "100 Main Street\nAnytown, CA 98765");

      Invoice samsInvoice = new Invoice(sam);
      samsInvoice.addItem(new Item("Toaster", 3, 29.95));
      samsInvoice.addItem(new Item("Hair dryer", 1, 24.95));
      samsInvoice.addItem(new Item("Car vacuum", 2, 19.99));
      samsInvoice.print();           
   }
}

/**
   Describes an invoice for a set of purchased items.
*/

class Invoice
{  /**
      Constructs an invoice for a customer.
      @param c the customer
   */
   public Invoice(Customer c)
   {  theCustomer = c;
      items = new Vector();
   }
   
   /**
      Adds an item to this invoice.
      @param anItem the item to add
   */
   public void addItem(Item anItem)
   {  items.add(anItem);
   }

   /**
      Prints the invoice.
   */
   public void print()
   {  System.out.println("               I N V O I C E");
      System.out.println();

      theCustomer.print();
      System.out.println();

      System.out.print("Item                          ");
      System.out.println("Qty Price   Total");
      
      for (int i = 0; i < items.size(); i++)
      {  Item nextItem = (Item)items.get(i);
         nextItem.print();
      }

      System.out.println();
      System.out.println("AMOUNT DUE: $" + getAmountDue());
   }

   /**
      Computes the total amount due.
      @return the amount due
   */
   public double getAmountDue()
   {  double amountDue = 0;
      for (int i = 0; i < items.size(); i++)
      {  Item nextItem = (Item)items.get(i);
         amountDue = amountDue + nextItem.getTotal();
      }
      return amountDue;
   }
   
   private Customer theCustomer;
   private Vector items;
}

/**
   Describes a customer with a mailing address.
*/