ITI 1220 Fall 2005 Assignment 8

Available:  Tuesday November 22

Due:  Friday December 2, noon

Instructions

This assignment is to be done in TEAMS OF TWO PEOPLE.  The assignment should be submitted only once by a member of your team, but please ensure that the identification material contains the information for both team members.  Follow the assignment submission instructions and coding guidelines from the course lab manual.

Marking scheme:

Background

In this assignment, you are going to be developing several classes that will work together to implement the “Air Kilometres” (AirKM) reward points program.  An AirKM card holder can earn points by making purchases of various items.  When sufficient points are earned, the points can be redeemed for free items.

Question 1 (20 marks)

In this question, you will design a class Product to store information related to items that can be purchased, or which can be obtained by collecting a sufficient number of reward points.

Attributes:

An instance of Product has the following attributes:

Constructor:

The constructor for a product should specify values for each of the attributes.  Specifically, the header should be as follows:

public Product( String theName, double theCost, int thePointsRequired )

Accessor methods:

You should provide accessor methods for each of the attributes, but no modifier methods. The method headers should be as follows:

 

public String getName( )
public double getCost( )
public int getPointsRequired( )

Test

Test your Product class using the class A8Q1.java, which should produce the results A8Q1.txt exactly.  Be sure that you use the class A8Q1.java without modification. You should also test your class with other situations using your own main method, or using JUnit tests.

Question 2 (20 marks)

Design a class CardHolder for storing information about a client of the loyalty program who would make purchases of instances of the Product class.  A UML class diagram for the class is below:

The attributes for each CardHolder object are below:

 

When a CardHolder object is created, the name and card number are provided, but the number of points should be initialized automatically to 0.

 

You should also provide accessors for the name and card number.  The number of points can be set directly or modified based on the current value.

Additional methods:

You can add other additional methods as needed, as long as the methods are private.

Test

Test your CardHolder class using the class A8Q2.java, which should produce the results A8Q2.txt exactly.  Be sure that you use the class A8Q2.java without modification. You should also test your class with other situations using your own main method, or using JUnit tests.

Question 3 (35 marks)

In this question, you will create a class Transaction that will store information about a specific purchase, or redemption of points.  An instance of the class will associate a specific CardHolder with a collection of Product items obtained as part of the transaction.


Attributes

There are values that are applicable to all Transaction objects:

 

For individual Transaction objects, the following information should be stored:

 

Constructor:

 

To create a transaction, only a reference to a CardHolder is specified.  Other values in the Transaction should be set to appropriate “safety” values.  In particular, the category of the transaction should be set to INCOMPLETE until additional information is provided from other methods.

 

Accessor methods:

 

You should provide accessor methods for the category, the transaction number, the number of points in the transaction, and the amount paid.

Additional methods:

 

// Do the following once

 

String newLine;

newLine = System.getProperty(″line.separator″);

 

// Do the following as needed

String aMessage;

aMessage = ″Line 1″ + newLine + ″Line 2″;

 

NOTE: Be sure to use the method headers that are specified, and that your message formats conform with those in the sample output in A8Q3.txt.

Test

Test your Transaction class using the class A8Q3.java, which should produce the results A8Q3.txt exactly.  [You will need at least part of the AirKM class developed in question 4 to get the value of POINTS_FACTOR, which has initial value of 1.] Be sure that you use the class A8Q3.java without modification. You should also test your class with other situations using your own main method, or using JUnit tests.

 

Question 4 (35 marks)

To manage the Air Kilometres system, one needs to maintain a list of products and transactions in order to handle various requests for information.  This will be done with the class AirKM.  Associated with this class is the following information:

 

 

The value for POINTS_FACTOR should be public; the other values should be private.

 

It is important to keep only a single catalogue and journal, so this will be accomplished as follows.  The class AirKM will have only class variables and methods, which means that AirKM objects should not be created.  Instead, the single catalogue and journal will be kept with the class, and all variables and methods will be declared as static.

 

Eight methods should be provided.  For descriptions of any error messages, see the file A8Q4.txt.

 

·         initialize(...):

o        Takes one integer parameter representing the maximum number of entries expected in either of the catalogue or journal arrays.  This method should create new arrays of the specified size for each of the catalogue and journal.  It also should set the number of actual items in the catalogue to be zero and the number of transactions in the journal to be zero.

·         setPointsFactor(...):

o        Takes two parameters:  an integer and a string.  This method allows the modification of the value POINTS_FACTOR which represents the value by which all points earned are multiplied and prints a confirmation of the change – but only if two conditions are met.  The first condition is that the new value of POINTS_FACTOR must be 1, 2, or 3.  Second, the caller must provide the correct password.  The string parameter is the guess at the password.  The password guess must be equal to ″ITI 1220 rules!″; if not, an error message should be displayed and the points factor should keep its original value.

·         addProduct(...)

o        Takes one parameter which is an object of type Product, and adds the product item to the catalogue.  If the catalogue is full – that is, the number of items already stored has filled the array, an error message should be printed.  The method should return true if it was able to add the new product item, and false if it could not.

·         getCatalogue(...)

o        Takes one integer as a parameter which represents an array index (0, 1, ...).  The method should return the Product object found at the array index in the catalogue.  If the index is too large, an error message should be printed, and the value null returned.

·         public static Boolean addTransaction(CardHolder client, int theCategory, Product[] items)

o        This method will first check to see if the journal has space for one more Transaction.  If the journal array is full, an error message should be printed and the method should return false.  If the journal array is not full, then a new Transaction object should be created using the information from the parameters.  The Transaction is then stored in the journal, and the method should return true.

·         addSingleProductTransaction(...)

o        This method is similar to addTransaction, except that the third parameter is a single Product object instead of an array of Product objects, and the method would be used when only one Product is involved in the transaction.  Consider having this method set up a call to addTransaction() to perform the function.

·         printTransactionsForCardHolder(...)

o        Takes a single parameter which is a String, representing the name of an Air Kilometres card holder.  The method should print each Transaction contained in the journal that is associated with a CardHolder for which the name matches the given value.

·         printSummary(...)

o        There are no parameters or return values for this method.  This method prints some summary statistics determined from the set of Transaction objects stored in the journal.  See A8Q4.txt for format details.

o        For purchases:  the number of purchase transactions, the total amount of all purchases, and the total number of points awarded to card holders.

o        For redemptions:  the number of redemption transactions, and the total number of points used.

You can add additional helper methods as needed.  Be sure that the method headers of the methods described above are used exactly, as the test program A8Q4.java will call the methods and use the return values.

Test

Test the four classes developed for this assignment using the class A8Q4.java, which should produce the results A8Q4.txt exactly.  Be sure that you use the class A8Q4.java without modification. You should also test your classes with other situations using your own main method, or using JUnit tests.

 

Class Diagram

Below is a UML class diagram showing the relationships among the classes in the assignment.  The solid line represents an association between classes, while the dashed line indicates a dependency on another class.  Diagrams such as the following are used to help identify relationships in complex object-oriented applications.