// This program tests the class Purchase

class A5Q3
{
   public static void main (String[] args) 
   { 
    // DATA DECLARATIONS
       Client larry, grace;
       Item book1, book2, dvd1, dvd2, game;
       Purchase purchase0, purchase1, purchase2, purchase3, purchase4;
       boolean résultat;       

    // IDENTIFICATION
       System.out.println("Question 3: Test of the class Purchase");
       System.out.println();

    // ALGORITHM BODY
       // Create some users and items
       larry  = new Client("Larry O'Brien", "larry@obrien.ca", "Noël");
       grace  = new Client("Grace Hopper", "grace@coldmail.org", "Informatique");
       book1  = new Item(Item.BOOK, "Da Vinci Code", 12, 3);
       book2  = new Item(Item.BOOK, "Garfield", 5, 2);
       dvd1   = new Item(Item.DVD, "Harry Potter III", 15, 5);
       dvd2   = new Item(Item.DVD, "Schindler's List", 20, 1);
       game   = new Item(Item.GAME, "HALO 2", 35, 2);

       // Test a purchase whose total cost is smaller than the credit
       Item[] items0 = {book2};
       purchase0 = new Purchase( larry, 1, items0 );
       
       // Test the printing of the credited amount
       System.out.print(purchase0);
       System.out.println("Remaning credit for " + purchase0.getClientName() 
                           + " : " + larry.getCredit() + "$");
       System.out.println( "There is " + book2.getCopiesAvailable() 
                           + " copy of " + book2.getTitle() + " available");
       System.out.println();
       
       // Test a purchase
       Item[] items1 = {book1, book2, game};
       purchase1 = new Purchase( larry, 1, items1 );

       System.out.println(purchase1);
       System.out.println( "There are " + book2.getCopiesAvailable() 
                           + " copies available " + book2.getTitle() );       
       // Test some accessors
       System.out.println("Bill #" + purchase1.getBillNumber()
                          + ", cost: " + purchase1.getTotalCost()
                          + "$, purchased on day: " + purchase1.getDatePurchased() );
       System.out.println("Remaining credit for " + purchase1.getClientName() 
                           + " : " + larry.getCredit() + "$");
       System.out.println();
       
       // Test other purchases and includesItem
       Item[] items2 = {dvd1, dvd2, game};
       purchase2 = new Purchase( grace, 2, items2 );
       System.out.println(purchase2);
       
       Item[] items3 = {dvd1, book2}; // Note: there is no more Garfield available...
       purchase3 = new Purchase( larry, 4, items3 );
       System.out.println(purchase3);
       
       System.out.println( dvd1.getTitle() + " purchased in purchase0? " + purchase0.includesItem(dvd1) );
       System.out.println( dvd1.getTitle() + " purchased in purchase1? " + purchase1.includesItem(dvd1) );
       System.out.println( dvd1.getTitle() + " purchased in purchase2? " + purchase2.includesItem(dvd1) );
       System.out.println( dvd1.getTitle() + " purchased in purchase3? " + purchase3.includesItem(dvd1) );
       System.out.println();

       Item[] items4 = {game};
       purchase4 = new Purchase( larry, 8, items4 );
       System.out.println(purchase4);
       System.out.println("Credit for " + larry.getName() + ": "
                           + larry.getCredit() );
   }
}
