/**
 * ITI 1220 Fall 2005, Assignment 8, Question 4
 * 
 * Program to test the 'AirKM' class, and other classes used by it.
 * 
 * @author Alan Williams
 */
public class A8Q4
{
	/**
	 * Main method to start test program.
	 * 
	 * @param args Command line arguments.
	 */
	public static void main( String[] args )
	{
		// DECLARE VARIABLES / DATA DICTIONARY
		
		CardHolder bob;
		CardHolder grace;
		Product aProduct;
		
		Product[] list1;
		Product[] list2;
		
		boolean result;
		
		// PRINT IDENTIFICATION INFORMATION
		
		System.out.println( "Question 4: Test for the class AirKM" );
		System.out.println( );
		
		
		// BODY OF ALGORITHM
		
		// Create some card holders
		
		bob = new CardHolder( "Bob Hope", 1234 );
		grace = new CardHolder( "Grace Hopper", 5678 );
		
		
		// Initialize the journal and catalogue.
		
		AirKM.initialize( 5 );
		AirKM.printSummary( );
		
		// Add some products to the catalogue;
		
		AirKM.addProduct( new Product( "Ottawa-Cuba", 1199.99, 250000 ) );
		AirKM.addProduct( new Product( "Ottawa-Toronto", 300.00, 60000 ) );
		AirKM.addProduct( new Product( "Harry Potter VI", 29.99, 7500 ) );
		AirKM.addProduct( new Product( "The Mythical Man-Month", 49.99, 9500 ) );
		AirKM.addProduct( new Product( "Quake 4", 59.99, 10000 ) );
		
		// See what is in the catalogue at index 2.
		
		aProduct = AirKM.getCatalogue( 2 );
		System.out.println( aProduct.getName( ) + ": " + "$" + aProduct.getCost( )
				+ ", " + aProduct.getPointsRequired( ) );
		
		// Add a product when the catalogue is full.
		
		AirKM.addProduct( new Product( "One too many...", 9.99, 2000 ) );
		
		// Try changing the points factor
		
		AirKM.setPointsFactor( 2, "incorrect password" );
		System.out.println( "Points factor: " + AirKM.POINTS_FACTOR );
		AirKM.setPointsFactor( 4, "ITI 1220 rules!" );
		System.out.println( "Points factor: " + AirKM.POINTS_FACTOR );
		AirKM.setPointsFactor( 3, "ITI 1220 rules!" );
		System.out.println( "Points factor: " + AirKM.POINTS_FACTOR );
		System.out.println( );
		
		// Create a transaction, and then print journal.
		
		list1 = new Product[2];
		list1[0] = AirKM.getCatalogue( 2 );
		list1[1] = AirKM.getCatalogue( 3 );
		
		result = AirKM.addTransaction( bob, Transaction.PURCHASE, list1 );
		AirKM.printSummary( );
		
		
		// Test of a purchase transaction with only one product.
		
		result = AirKM.addSingleProductTransaction( grace, Transaction.PURCHASE, AirKM
				.getCatalogue( 0 ) );
		AirKM.setPointsFactor( 1, "ITI 1220 rules!" );
		result = AirKM.addSingleProductTransaction( grace, Transaction.PURCHASE, AirKM
				.getCatalogue( 4 ) );
		AirKM.printTransactionsForCardHolder( grace.getName( ) );
		
		// Test of a redemption transaction with only one product.
		
		result = AirKM.addSingleProductTransaction( grace, Transaction.REDEMPTION, AirKM
				.getCatalogue( 3 ) );
		System.out.println( result );
		
		// Test of a single product redemption transaction with not enough points.
		
		result = AirKM.addSingleProductTransaction( grace, Transaction.REDEMPTION, AirKM
				.getCatalogue( 1 ) );
		System.out.println( result );
		
		
		// Test of a multiple product redemption transaction with not enough points.
		
		list2 = new Product[2];
		list2[0] = AirKM.getCatalogue( 4 );
		list2[1] = AirKM.getCatalogue( 3 );
		result = AirKM.addTransaction( bob, Transaction.REDEMPTION, list2 );
		System.out.println( result );
		
		
		// Test of a successful multiple product redemption transaction.
		
		result = AirKM.addTransaction( grace, Transaction.REDEMPTION, list2 );
		System.out.println( result );
		
		// Try to add a transaction when the journal is full.
		
		result = AirKM.addTransaction( bob, Transaction.PURCHASE, list2 );
		System.out.println( result );
		System.out.println( );
		
		
		// Test reporting methods.
		
		AirKM.printSummary( );
		AirKM.printTransactionsForCardHolder( grace.getName( ) );
		AirKM.printTransactionsForCardHolder( bob.getName( ) );
		AirKM.printTransactionsForCardHolder( "Unknown" );
	}
}
