For this project, your goal is to write a simple bank imitation program that users can interact with.

You will write three classes: BankAccount, Bank, and BankMenu.

BankAccount class

Fields

firstName -- First Name
lastName -- Last Name
address -- Address
balance -- Account Balance (in whole dollars)
userName -- Account Username (unique)
pin -- PIN (used as a password)

Methods

Getters

getFirstName()
getLastName()
getAddress()
getBalance()
getUserName()
getPIN()

Setters

setFirstName(firsName)
setLastName(lastName)
setAddress(address)
setUserName(username)
setPIN(pin)

Other

addBalance(amount)
subtractBalance(amount)
isValidName(name) -- check whether the first (or last) name is valid
isValidUserName(userName) -- check whether a username is valid
isValidPIN(pin) -- check whether a pin is valid

Bank class

Fields

accounts -- array of BankAccount objects
name -- Name of the bank
numAccounts -- number of bank accounts in the accounts array

Methods

getAccount(userName, pin) -- return a BankAccount identified by the name userName (if found and confirmed with PIN). Return null otherwise (and print appropriate error messages).

registerAccount(account) -- add a bank account. Make sure the username is not a duplicate. Validate fields where appropriate.

terminateAccount(userName, pin) -- terminate (remove) a bank account. Print an error message if the username doesn't exist or the PIN is incorrect.

accountExists(userName) -- return true if the account with the specified user name exists; return false otherwise.

grow() -- internal function that will extend the capacity of the accounts array.

BankMenu class

All of the methods in the BankMenu class should be static.

Methods

landingMenu(bank)
This method should show this menu:
1. Log in
2. Sign up
3. Terminate account
4. Exit

loginMenu(bank)
This method should prompt the user for their username and PIN. It should enter the main menu if the entered information is correct, and it should return to login menu otherwise.

signupMenu(bank)
This method should prompt the user to enter all of the necessary details to register a new account. For the username, the method should search the bank to make sure that such username hasn't already been registered.

terminateAccountMenu(bank)
This method shoud prompt the user to enter account username and PIN. A final confirmation dialog ("Are you sure you want to terminate your account? [Y/N]") should be printed before terminating (removing) the account.

mainMenu(account)
This method should greet the user ("Welcome, ...!") and then print this menu:
1. Deposit Money
2. Withdraw Money
3. Account Details
4. Exit

depositMenu(account)
This method should prompt the user to enter the amount of money to deposit and add the entered amount appropriately. Only positive numbers should be allowed.

withdrawMenu(account)
This method should prompt the user to enter the amount of money to withdraw and withdraw the entered amount appropriately. Only positive numbers should be allowed. Quite obviously, the user should not be allowed to withdraw more money than they currently have in their account.

accountMenu(account)
This method should print all of the account details and then show the user the following menu:
1. Change First Name
2. Change Last Name
3. Change Address
4. Change Username
5. Change PIN
6. Exit

changeFirstNameMenu(account)
Prompt the user to enter their PIN again and then print a prompt that asks the user for their new First Name. Validate the name using the isValidName method from the BankAccount class.

changeLastNameMenu(account)
Same as changeFirstNameMenu, except that the information to change is the Last Name.

changeAddressMenu(account)
Same as changeFirstNameMenu, except that the information to change is the Address.

changeUsernameMenu(account)
Same as changeFirstNameMenu, except that the information to change is the Username.

changePINMenu(account)
Same as changeFirstNameMenu, except that the information to change is the PIN.

promptPIN(account)
Prompt the user for their PIN and return true if the entered PIN matches the account. Return false otherwise.

Overall Notes

  • Exercise defensive programming where appropriate. Whenever you are getting input from a user, ensure that what they entered is valid.
  • Print error messages when some error occurs. Try your best to make them informative.
  • Print messages for logging what is happening (e.g. "Confirming password...", "Logging in...", "Withdrawing $20" etc.). This will help you keep track of what is going on in the program; it will speed up your debugging process. On top of that, the user will be aware that the system is working -- it will seem much more interactive with all the feedback on the screen.
  • Start by implementing and testing the simplest components first. For example, BankAccount class might be the easiest one.
  • Write helper/convenience methods whenever you feel like there is code repetition going on. Keep your methods as short as you can.
  • Each of the menu methods should keep re-printing the menu until the "exit" option is chosen. Invalid menu selection should be rejected (with an appropriate error message)
  • Create appropriate constructors for the classes that need them. Create copy constructors to have an option to deep-copy information
  • You can think of the menu functions as a tree:
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.