There has been a catastrophic system crash in the data warehouse for the bank where you are employed. The servers which maintained the current account balance information of our customers has experienced unrecoverable errors. Luckily the transaction data (deposits and withdrawals) are stored separately and remain intact.

You are tasked with writing a program to read in data files containing this transaction information of all our customers and reporting the current balances of each account of each customer.

Customer Class

The Customer class is provided but needs to be modified. Since it will be used later as a key type, it must override the hashCode() and equals() methods.

Different customers could have the same name and while extremely unlikely, they could also have the same birthday. But it is unlikely that two different customers will have the same name, birthday, and year they first became a customer. This class will use all three to uniquely identify a customer.

Two instances of Customer are considered equal if:

  • The values of the name field are equal
  • The values of the dateOfBirth field are equal
  • The values of the customerSinceYear field are equal

The hashCode() method should return the same value for any two Customers that are equal.

  • Implement the hashcode method according to the polynomial hash code pattern described in section 28.3.2 where s0 is a starting value (such as 1), s1 is the hashcode of the first field, s2 is the hashcode of the second field, and so on.
  • In order to match equals, hashcode calculation should include the hashcodes of the fields:
    • name
    • dateOfBirth
    • customerSinceYear

AccountType Enumeration

A customer may hold different types of accounts at this bank. The AccountType class defines the types of accounts that the bank services (This enumeration is provided should not be modified in any way):

  • Checking
  • Savings
  • Loan

AccountBalances Class

Each customer may hold up to one account of each type. The AccountBalances class maintains the running balances of each type of account for a single customer. The AccountBalances class should be flexible so that changes are not required if additional account types are added to the AccountType Enumeration in the future.

To enable this flexibility, use a Map with:

  • AccountType as the keys. If present in the map, the customer has an account of that type.
  • Double as the values. Represents the current balance of the customer’s account of that type.

The map should be initially empty for new instances of AccountBalances. As transactions are processed (see CustomerDataRestore section below), accounts will be added to this map and the balance values updated by calls to this class.

  • Implement the method: public void addToBalance(AccountType type, double change)
    • Add the provided change value to the balance for the account of the provided type.
    • If this customer does not have an account of the provided type (i.e. it does not appear in the map), assume it started with value 0 before adding this change.
  • Implement the method: public boolean hasAccount(AccountType type)
    • Returns true if the customer for this instance of AccountBalances has an account of the provided type (i.e. it appears in the map).
  • Implement the method: public double getBalance(AccountType type)
    • Returns the current balance of the account of the provided type.
    • It is safe to assume that this will only ever be called for types for which hasAccount returned true.
  • Implement method: public int getNumAccounts()
    • Returns the number of accounts the customer for this instance of AccountBalances has (i.e. the number of balances kept in the map).
  • Override toString for this class to return a String which contains the current balance of each account the customer holds.
    • They should each be separated by a “n” so they appear on separate lines when printed. For example: Checking=180.0 Savings=50.0 Loan=-1000.0
    • To maintain the flexibility to future changes to AccountType, loop over the map using keys returned by AccountType.values().
    • If the customer does not have an account of a type, do not include it in the result.

CustomerDataRestorer Class

The CustomerDataRestorer class is the program that will read a transaction log file to recover the current account balance information for all of our customers and print some useful information.

Management has identified a set of immediate data requirements to recover from the transaction log right away. They have specified these requirements by sketching out a main method that calls a sequence of methods to be implemented (see below).

  • The main method for this program is provided and should not be modified.
    • This program expects one argument The path to the transaction log file to process
    • The program creates an instance of the CustomerDataRestorer class and calls a sequence of methods to obtain the answers to the immediate data needs (see below).

The developer of the application which generates the transaction logs has provided a sample of the data (SampleAccountLog.txt) for you to work with as well as some helper methods for parsing lines of log data.

  • The following helper methods are provided and should not be modified: parseCustomer, parseAccountType, and parseChange.
    • Each accepts an argument containing a full line of the transaction log and returns the corresponding piece of that line as instances of the domain data types.
    • The transaction log line should be split on Tab characters and the whole resulting token array passed to each of these methods (e.g. line.trim().split("t "))

Implement the following methods in CustomerDataRestorer to complete the program:

public void restoreFromTransactions(File file) throws IOException

For each line of the input file, this method:

  • Splits the line (e.g. line.trim().split("t "))
  • Provides the resulting token array to the helper parse methods to obtain an instance of Customer, AccountType, and a double balance change value (positive is deposit).
  • Updates a Map with this new transaction:
    • The Map should use: the instance of Customer as the key and an instance of AccountBalances as the value.
    • Hint: if this is the first time this key has been seen, add a new instance of AccountBalances to the map for it.
    • Hint: addToBalance(AccountType, double) to record the transaction

public void printAllBalances()

  • For each customer in the Map, print the customer and their account balances.
    • Hint: use the toString methods of Customer and AccountBalances
  • These should be printed in the order each customer first appears in the transaction log
    • Hint: Using the right implementation of Map will provide this order on iteration.
  • For example: Irish Eaker (DOB: Mon Jun 11 00:00:00 EDT 1979, Customer since: 2009) Savings=200.0 Loan=0.0

public int getNumCustomers()

  • Returns the number of customers restored into the map.

public int getNumAccounts()

  • Returns the total number of accounts restored across all customers.

public int countRepaidLoans()

  • Returns the number of accounts of type Loan with a balance of at least 0.

public Collection getCustomersForLoanStatements()

  • Returns a collection of Customers that
    • have an account of type Loan
    • the Loan account has a balance less than 0.

The program output when run on SampleAccountLog.txt should appear as:

Rashida Straw (DOB: Wed Feb 25 00:00:00 EST 1959, Customer since: 2012)
Checking=180.0
Savings=50.0
Loan=-1000.0

Brittany Goodson (DOB: Fri Mar 24 00:00:00 EST 1961, Customer since: 2011)
Checking=20.0

Irish Eaker (DOB: Mon Jun 11 00:00:00 EDT 1979, Customer since: 2009)
Savings=200.0
Loan=0.0

Rashida Straw (DOB: Sun Jan 01 00:00:00 EST 1989, Customer since: 2012)
Checking=100.0

Brittany Goodson (DOB: Fri Mar 24 00:00:00 EST 1961, Customer since: 1999)
Loan=-300.0

Number of customers restored: 5
Number of accounts across all customers: 8
Number of loans repaid:1
Customers that require loan statements sent:
Rashida Straw (DOB: Wed Feb 25 00:00:00 EST 1959, Customer since: 2012)
Brittany Goodson (DOB: Fri Mar 24 00:00:00 EST 1961, Customer since: 1999)

The program output when run on FullAccountLog.txt should appear as (not all lines shown):
Rashida Straw (DOB: Wed Feb 25 00:00:00 EST 1959, Customer since: 2012)
Checking=180.0
Savings=50.0
Loan=-1000.0

Ernestina Kinlaw (DOB: Tue Jan 15 00:00:00 EST 1946, Customer since: 2004)
Checking=120.0
Savings=446.0
Loan=271.0

Number of customers restored: 108
Number of accounts across all customers: 300
Number of loans repaid:14
Customers that require loan statements sent:
Rashida Straw (DOB: Wed Feb 25 00:00:00 EST 1959, Customer since: 2012)
Brittany Goodson (DOB: Fri Mar 24 00:00:00 EST 1961, Customer since: 1999)

Abigail Suazo (DOB: Wed Aug 15 00:00:00 EDT 1979, Customer since: 2007)
Yoshie Cavin (DOB: Tue Jul 04 00:00:00 EDT 1961, Customer since: 2012)
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.