Lab 14

Readers and Writers for BankAccount Transactions


Introduction

For this lab you will implement some important utility classes: "readers" that know how to read Transactions and BankAccounts from files and a "writer" which knows how to write BankAccounts to a file . This lab reinforces the idea of substitution, but it also reinforces the idea of decentralizing responsibilities. Instead of placing file reading and writing behavior in our client classes, we will create objects that can read and write files containing specific kinds of objects. This reduces the complexity of client code while at the same time making the client code less dependent on the representation of the objects that it uses.

When you are done, you will have a graphical program that mimics a simple ATM.  When the program starts a previously existing set of Transactions (a BankAccount) will be loaded into the ATM from an input file.  The ATM will allow simple, whole dollar Deposits and Withdrawals to be made.  When a provided button on the ATM is pressed, the set of Transactions (the BankAccount), including both the original Transactions and the new Transactions, will be written to an output file.

 

Why this lab will frustrate you

This lab will drive some of you crazy for two reasons:

  1. I am going to ask you to use several classes you haven't read about and we haven't talked about in class (Calendar and FileWriter at a minimum).
  2. The directions seem kind of cryptic at times.  I tell you to build some class that will likely make no sense to you on first pass because you can't see the big picture yet.

While you may think I am being unreasonable, I am doing this for a reason.

  1. You are going to get asked to modify code you haven't seen before that uses things you have never seen before.  Your job is to check out the API as necessary and figure it out.
  2. I could let you stumble around trying to find a working solution, but I want you to design a GOOD solution.  The directions have you write what is, I think, a nicely written solution for this problem domain.  When you are done, go back and look at WHY this IS a good solution.

 

Getting Started

To begin with you will need to download the following starter code

This is based on a working solution to Lab 12 .  Check out the following classes:

And then run BankAccountDemo to remind yourself how this works.

You don't need to know a lot about Calendar to understand how to use it in this lab.  Check out how I use it, and refer to this code as needed to solve this lab.

 


Tasks

The code you have started with is a simple "hard coded" example.  Now your boss wants you to take this code and make it more like an actual banking application.  That is, we need long term storage of data (file I/O) and something more like an ATM.  You remember the "Accumulator" that we used earlier in the semester and decide to modify that to look something like an ATM (this part has done for you, mostly). 

Complete this object-oriented program by doing the following:

  1. Implement a TransactionReader class. A TransactionReader is an object that can read Transactions from a file.

    The TransactionReader class should provide:

    Your class must be able to read the three Transaction types provided by the starter code (deposit, withdrawal, and service charge) and contained in the file named "transactions1.txt"

     

  2. Implement a BankAccountReader class. A BankAccountReader uses a TransactionReader to read a stream of Transactions into BankAccount. A BankAccountReader should provide at least these services:

    When you think you have parts one and two working, compile and run BankAccountPartTwoDemo.java and see if your output makes sense.

     

  3. Implement a BankAccountWriter class. A BankAccountWriter should provide at least these services:
    
      
  4. When you are all done, you can test this by running Lab14 with the provided file as input, performing a few transactions on the ATM and then pressing the write button to save this to an output file.  THEN, run the code again using the output file from the first run as your input file in this run.  Is everything read in properly?

 


Deliverables

Zip all of these together into a single Lab14.zip file and submit: