/** * ITI 1220 Fall 2005, Assignment 8, Question 3 * * Program to test the 'Transaction' class. Requires the 'AirKM' class to * have implemented at least the POINTS_FACTOR value. * * @author Alan Williams * */ public class A8Q3 { /** * 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 book1; Product book2; Product ticket1; Product ticket2; Product game; Product[] list1; Product[] list2; Transaction trans1; Transaction trans2; Transaction trans3; boolean result; // PRINT IDENTIFICATION INFORMATION System.out.println( "Question 3: Test of the Transaction class." ); System.out.println( ); // ALGORITHM BODY // Create some card holder and product objects bob = new CardHolder( "Bob Hope", 1234 ); grace = new CardHolder( "Grace Hopper", 5678 ); ticket1 = new Product( "Ottawa-Cuba", 1199.99, 250000 ); ticket2 = new Product( "Ottawa-Toronto", 300.00, 60000 ); book1 = new Product( "Harry Potter VI", 29.99, 7500 ); book2 = new Product( "The Mythical Man-Month", 49.99, 9500 ); game = new Product( "Quake 4", 59.99, 10000 ); // Create a new transaction, and have the object print its information. trans1 = new Transaction( bob ); System.out.println( trans1 ); list1 = new Product[]{ game, book2, ticket1 }; result = trans1.purchase( list1 ); System.out.println( trans1 ); // Try some accessor methods System.out.println( "Transaction #" + trans1.getTransactionNumber( ) + ", category: " + trans1.getCategory( ) + ", card holder: " + trans1.getCardHolderName( ) + ", points: " + trans1.getPoints( ) + ", amount paid: " + trans1.getAmountPaid( ) ); System.out.println( ); // Test successful purchase. result = trans1.purchase( list1 ); System.out.println( result ); // Test successful points redemption. list2 = new Product[]{ book1, ticket2 }; grace.setNumberOfPoints( 68000 ); trans2 = new Transaction( grace ); result = trans2.redeemPoints( list2 ); System.out.println( trans2 + "Result: " + result ); // Test points redemption with too few points. grace.setNumberOfPoints( 67000 ); trans3 = new Transaction( grace ); result = trans3.redeemPoints( list2 ); System.out.println( trans3 + "Result: " + result ); } }