SE-1011 Software Development 1
Lab 7: BankAccount class

Outcomes

Assignment

In this lab, you will add additional functionality to the BankAccount user-defined custom class begun in the past few lectures. In particular, you will add more attributes and methods to the class so that it conforms to the BankAccount class illustrated in the following UML (Unified Modeling Language) class diagram:

Observe that this UML class diagram also illustrates the main class, ClassCreatorApp, which contains no attributes and only the single static main() method. It also illustrates an association between the two classes: the dotted arrow indicates that the main class uses the BankAccount class.

Detailed requirements

Your application must consist of a main class called ClassCreatorApp, in a package named msoe.se1011.<your msoe email name>, as well as the BankAccount class, in a package named msoe.se1011.bankaccount.

Begin by adding the additional attributes and methods to the BankAccount class that we started in the previous lectures. Pay close attention to the syntactical details of the UML class diagram. Refer to page 200 in the textbook for an introductory explanation of class diagrams, and look at page 278 for some additional examples. Note that the underlined attributes and methods are static. The <property get> and <property set> annotations are a kind of UML "comment" - these annotatons are just indicators that the methods that follow are "getters" (Accessors) and "setters" (Mutators). Refer back to section 6.12 of the textbook for more information on Accessors and Mutators.

The UML diagram allows you to determine the properties of the attributes, as well as the signatures of the methods. However, it doesn't reveal what each method does. You already know what the withdraw() method's purpose is, but for the others, you'll have to read this pdf document, which contains descriptions of the purpose of each method, its arguments, and return value, along with some notes on how the method behaves. Be sure to incorporate this information into your implementation in the form of comments demonstrated in class.

Note the history attribute of the BankAccount class. This is an instance variable that contains a log of every transaction made to the account, which is updated within the methods applyInterest(), withdraw(), and deposit(), along with the constructor BankAccount(). The history is first initialized when the account is constructed, and each subsequent method causes that transaction to be appended.

Once you have completed the BankAccount class implementation, turn to the ClassCreatorApp class's main() method. Within that method, add instructions that correspond to the following pseudocode:

  1. Create a BankAccount object named mySavingsAcct representing Savings account number S123-00 and containing $100 initially.
  2. Create a BankAccount object named myCheckingAcct, representing Checking account number C456-99 and containing -$200 initially.
  3. Withdraw $10 from Savings.
  4. Withdraw $20 from Checking.
  5. Print the transaction history for the Savings account.
  6. Print the transaction history for the Checking account.

At this point, run the program. The output it generates should look like this (note the formatting of the dollar values):

    Savings account S123-00 created with default balance of $100.00 
    Withdrew $10.00, new balance: $90.00 

    Checking account C456-99 created with default balance of $0.00 
    NSF: attempt to withdraw $20.00, new balance: $0.00 

Add the following additional instructions to the main() method:

  1. Deposit $100 to Savings.
  2. Withdraw $1000 to Checking.
  3. Print the transaction history for the Savings account.
  4. Print the transaction history for the Checking account.
  5. Set the interest rate for all accounts to 5%.
  6. Apply the interest to Savings.
  7. Apply the interest to Checking.
  8. Print the transaction history for the Savings account.
  9. Print the transaction history for the Checking account.

At this point, run the program again. The output it generates should look like this - note that there are three groups of output (colored differently here so you can tell them apart) that result from each invocation of the method you call to print the transaction history.

    Savings account S123-00 created with default balance of $100.00 
    Withdrew $10.00, new balance: $90.00 

    Checking account C456-99 created with default balance of $0.00 
    NSF: attempt to withdraw $20.00, new balance: $0.00 
	

    Savings account S123-00 created with default balance of $100.00 
    Withdrew $10.00, new balance: $90.00 
    Deposited $100.00, new balance: $190.00 

    Checking account C456-99 created with default balance of $0.00 
    NSF: attempt to withdraw $20.00, new balance: $0.00 
    Deposited $1000.00, new balance: $1000.00 
	

    Savings account S123-00 created with default balance of $100.00 
    Withdrew $10.00, new balance: $90.00 
    Deposited $100.00, new balance: $190.00 
    Interest earned: $9.50; new balance: $199.50 

    Checking account C456-99 created with default balance of $0.00 
    NSF: attempt to withdraw $20.00, new balance: $0.00 
    Deposited $1000.00, new balance: $1000.00 
    Interest earned: $50.00; new balance: $1050.00	

Note that you may not have to use every method you implemented in the BankAccount class to implement the above pseudocode.

You should also incorporate additional instructions into your main method so that you can verify that, for example, trying to deposit or withdraw a negative amount fails, or that setting an interest rate that is out of range fails correctly.

Lab Submission (due date in WebCT)

Submit your assignment following these instructions:

  1. Upload your .java file through WebCT (assignment "Lab 7: BankAccount").
Be sure to keep copies of all your java files, in case something gets lost.

Your grade will be based on the following criteria: