Program Specifications
Youre asked to write a program to analyze (or report) a customers credit cards monthly purchase transactions. The program is to read all customers transactions from a text file and store them in an array of transactions. A transaction can be a Banking transaction, or a Department Store transaction, or a Grocery transaction. Each transaction may qualify for reward points. In other word a transaction is rewardable. The program will build another array of Rewardable objects which are in fact the transactions objects themselves. Finally the program will generate two reports: one is to list all transactions and the other is to produce a summary report of reward points for the customer.
The below diagram shows how the arrays of Transactions and arrays of Rewardable look like:
The assignment basically illustrates the following concepts:
Inheritance
Abstract classes
Polymorphism
instanceof
Interfaces
Class Design
You need to have at least the following classes described below. Feel free to come up with more classes if needed.
public class CreditCardTransactionAnalyzer
This class is the public class containing the main method
The main method should do the following:
Instantiate a Customer object using non-default constructor
Invoke readTransactions
Invoke reportTransactions
Invoke reportCharges
Invoke reportRewardSummary
class Customer(minimum implementation specified below)
Private instance fields
Customer name
Credit card number (16-digit String)
Transaction balance (total balance)
Reward points balance
Array of references to Transaction objects (size 16 use private static constant integer field initialized to 16)
Array of references to Rewardable objects (size 16 see above)
Public Constructors: default and non-default constructors similar to previous assignments (setting total balance to 0.0 and reward points balance to 1000 by default)
Public instance methods:
readTransactions: read a text file containing Transactions with format shown below.
Based on transaction type (GS, BK, or DS) instantiate the correct sub class object and assign it to the array of Transactions
Each sub class object can potentially be a Rewardable object (Grocery and Department Store). Use instanceof to determine if thats the case then assign it to the array of Rewardable object. Note that you do not isntantiate new objects for the Rewardable array. It simply make references to the array of Transaction objects (see diagram above)
NOTE: The array of Rewardable objects will have less non-null objects than the Transaction array.
Text file format: (you must create a text file containing exactly 16 transactions)
BK~03/12/18~2222~300.0~ATM~6.00
GR~04/20/18~4444~57.95~Lucky
BK~05/01/18~5555~100.0~CASH~4.00<<<<<< withdraw $100, service charge $4.00GR~04/23/18~6666~17.39~SafewayDS~04/01/18~7777~211.67~Sears~90NOTE:DS: Department Store transactionBK: Banking transactionGR: Grocery transactionreportTransactions (this is generically processing): invoke the list method for each Transaction in the Transaction array. This should list all transactions’ information.Must use the new enhanced for loop syntax. TRANSACTION LISTING REPORT04/23/18 Department Store Macys $ 25.67 (return in 60 days)03/12/18 Banking ATM withdraw $30604/20/18 Grocery Lucky $57.95etc …reportCharges (this is specifically processing): go thru the entire Transaction array. If a transaction is a Banking one then compute the total charges and then display it. Simply display one line: Total charges: $XYZreportRewardSummary (this is process objects implementing the same interface) : invoke the earnPoints to compute total points for different transaction category from the Rewardable array to prepare the report summary below.Must use the new enhanced for loop syntax Rewards Summary for
Previous points balance 1000
+ Points earned on Department store purchases: 2710
+ Points earned on Grocery Stores purchases 750
–
= Total points available for redemption 4460
class Transaction:this is anabstract class
Private instance field: transaction id
Protected instance fields: transaction date (mm/dd/yy), transaction amount
Public Constructors
Public instance methods:
list: abstract method that will output transaction information (see TRANSACTION LISTING REPORT sample). This abstract method will be implemented in the sub classes.
toString: return a String of transaction id, transaction date, and transaction mount
equals: same transaction id and same date
accessors/mutators
NOTE: No transaction type instance field should be defined for any class, super class or sub classes. Point deduction will apply if thats the case.
Sub classes from Transaction:
DepartmentStoreTransaction: department name (Macys, Ross, Marshall, ), return policy (30 days, 60 days, or 90 days)
BankingTransaction: type (ATM withdraw or CASH withdraw), charge
GroceryTransaction: store name (Lucky, Walmart, Safeway, ..),
Keep those sub classes simple.Those sub classes will implement Rewardable interface as appropriate. Not all of them will.
At minimum they should have the following:
private instance fields
public default and non-default constructors (must explicitly use constructor chaining)
Note: The non-default constructors of those sub classes must take transaction date, transaction id, transaction amount (required by the superclass non-default constructor) in addition to parameters required by their own instance field.
accessor/mutator
toString
equals: for overloading equals must combine with the super class equals method using && logical operator
Provide implementation for the listing abstract method in the Transaction super class to display a transaction in the following format:
Date Transaction type Amount Specific info about transaction
Example:
03/12/16 BankingATM withdraw $306
Note: listing for Banking transaction must add the charge to amount
Interface Design
Provide an interface namely Rewardable with only one method: earnPoints that computes and returns total points earned for a particular transaction according to the following rules:
DepartmentStoreTransaction: 3 points per $1
GroceryTransaction: 5 points per $1
NOTE: Unrelated objects implement the same interface can be grouped together and processed the same way (via the interfaces contractual obligation). In this assignment we dont really demonstrate that capability. The Transaction objects that implement Rewardable interface are in fact related (within Transaction inheritance hierarchy). You may think in real life there could be other unrelated classes that can earn points such as MerchandiseAccount, FrequentFlyerAccount, etc and thus they will need to implement Rewardable interface. In that case we can group MerchandiseAccount, FrequentFlyerAccount, GroceryTransaction, DepartmentStoreTransaction altogether as Rewardable objects and compute their reward points. Just something for you to think about.
Testing:Run the program to verify if the reports are correct.
Extra Credit (5 points)
Implement Comparable interface for the abstract Transaction class with compareTo based on transaction amount. Sort the array of Transactions from low to high transaction amounts and output the results. For sorting youre encouraged to use Java utility. If you dont know it youre welcomed to write your own sorting algorithm. Note: you must implement Comparable
Reviews
There are no reviews yet.