Homework 5, Part A: Banks

Learning Goals:

Pair Assignments:

We will assign you a peer to collaborate with on this assignment. Please,

Specification

How to start

As you can see, this is a long description. It likely requires a lot of thinking before one starts writing code, otherwise one risks the possibility of writing a lot of code that addresses a different set of specifications.

We recommend that you start with keeping notes on paper and you draw the UML diagram of the classes you will need, along with their instance variables and their methods. Keep your UML diagram because you will need to submit it along with your code.

Problem Description

Design and write the basic software that will manage bank accounts and their required functionality. Below are the requirements that were provided to you by the bank manager, a Wellesley graduate with CS230 experience (and a passion for creating classes through inheritance ;-)

According to the bank specifications, a client can open a new account in the bank. With every new account opened, the Bank produces a unique account number to associate with that new account. There are two types of accounts in the bank:

The following requirements must be implemented in your software:

Design and Implementation of the application

Read the problem description above and design your application code. You should have exactly 4 classes. Think about inheritance when designing those classes. Some of these classes share a lot of characteristics.

To help you get started, here is a small description of one of the classes you should have in your application.

The Account class should contain all the common characteristics and functionality of any type of bank account. These include:

  1. the -unique for each account- account number
  2. the account balance
  3. deposit(): a method for depositing an amount to the account
  4. withdraw(): a method for withdrawing an amount from the account, and
  5. toString(): a method to be used for printing the account.

Notes:

  1. The withdraw() method behaves differently depending on the kind of the account. Therefore, think carefully: can you provide the definition for this method in the Account class? If not, where should it be defined?
  2. The toString() method behaves almost the same in both types of accounts, but in the case of a checking account it should also include the minimum balance, while in the case of a saving account it should include the interest rate.
  3. You can assume that the method to accrue interest, relevant only in Savings Accounts!, is called manually once a month; no need to keep track of dates. (Since the given interest rate is annual, make sure to calculate the monthly interest accordingly.)
  4. An account cannot be removed from the Bank once it has been added, and the maximum number of accounts that a Bank can hold cannot change.

Testing!

To show that your programs works correctly, you should create a main() method for each class that requires testing. Carefully think about what testing is relevant for each class. Your testing transcript should contain the correct/expected results next to the produced ones, so one can access correctness easier.

An example of running the Bank’s main method is given in our below, wherein, in brackets [like this] is the explanation of the transaction that follows:

Current state of Bank:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This bank currently manages 4 accounts: 
Checking  account num: 0	Balance: $1,000.00	Minimum balance: 100.0	Overdraft fee: 25
Savings   account num: 1	Balance: $1,000.00	Interest rate: 0.5
Checking  account num: 2	Balance: $500.00	Minimum balance: 100.0	Overdraft fee: 25
Savings   account num: 3	Balance: $500.00	Interest rate: 0.5
~~~~~~~~~~~~~~~~~~~~~~~~~~~ Total Funds: $3000.0

[Depositing $4000 into Checking #0. Should print Acct#0, Bal=$5000, Min=$100]
Checking  account num: 0	Balance: $5,000.00	Minimum balance: 100.0	Overdraft fee: 25

[Withdrawing $6K -- MORE THAN AVAILABLE from Checking #0]
** Withdrawal DENIED **: Insufficient balance.Checking  account num: 0	Balance: $5,000.00	Minimum balance: 100.0	Overdraft fee: 25

[Withdrawing $4901 from Checking #0 triggers Overdraft: Bal=$74.00]
** NOTE: Balance is low. Overdraft Fee was charged.
Checking  account num: 0	Balance: $74.00	Minimum balance: 100.0	Overdraft fee: 25

[Allowed Withdrawing $70 from Checking #0 triggers Overdraft: Bal=-$21.00]
** NOTE: Balance is low. Overdraft Fee was charged.
Checking  account num: 0	Balance: -$21.00	Minimum balance: 100.0	Overdraft fee: 25

[Withdrawing from NEGATIVE funds not allowed]
** Withdrawal DENIED **: Insufficient balance.Checking  account num: 0	Balance: -$21.00	Minimum balance: 100.0	Overdraft fee: 25

[Depositing $100 into Checking #0. Should print Acct#0, Bal=$79, Min=$100]
Checking  account num: 0	Balance: $79.00	Minimum balance: 100.0	Overdraft fee: 25

New state of Bank accounts:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This bank currently manages 4 accounts: 
Checking  account num: 0	Balance: $79.00	Minimum balance: 100.0	Overdraft fee: 25
Savings   account num: 1	Balance: $1,000.00	Interest rate: 0.5
Checking  account num: 2	Balance: $500.00	Minimum balance: 100.0	Overdraft fee: 25
Savings   account num: 3	Balance: $500.00	Interest rate: 0.5
~~~~~~~~~~~~~~~~~~~~~~~~~~~ Total Funds: $2079.0

[Depositing $2000 into Savings 1. Should print Acct#1, Bal=$3000, Int=0.5%]
Savings   account num: 1	Balance: $3,000.00	Interest rate: 0.5

[Withdrawing $5K MORE THAN AVAILABLE from Savings #1]
** Withdrawal DENIED **: Insufficient balance.
Savings   account num: 1	Balance: $3,000.00	Interest rate: 0.5

[Withdrawing $3K from Savings #1]
Savings   account num: 1	Balance: $0.00	Interest rate: 0.5

What to submit

Your Gradescope submission should contain the following:

  1. your java files
  2. your corresponding BankTesting.txt files that contain your testing results
  3. A PDF or PNG file of the UML diagram that corresponds to your solution.


Homework 5, Part B: Stacks

Learning goals

Task: Palindrome Checker using your preferred Stack implementation

A palindrome is a linear collection of objects that appear to be in the same order when you list them in either direction (first to last or last to first). In this task our palindromes will be strings.

Write a program PalindromeChecker.java that uses 1 or 2 stacks to determine if a string is a palindrome. You may want to use String.toCharArray in putting characters onto a stack.

Please depict how your algorithm works graphically (by drawing it and taking a picture of it). You will submit this at the end. Make sure to include all relevant information in this representation, so that a reader who is only familiar with the Stack interface understands your approach.

Specifications

You are expected to create your own test cases, and demonstrate that your code meets expectations. Remember that thorough testing implies identifying and testing boundary cases as well.

What to submit

Submit 3 files: your PalindromeChecker.java file, the picture describing your strategy in using stacks, and your testing PalindromeCheckerTesting.txt file.


Submission Checklist