Create a Bank Account Application in Java

 

Capture

Figure-1

This application will simulate a simple bank transaction terminal with a graphical user interface. You will be able to load multiple bank accounts and view their account holder’s name, account number, account open date, and account balance. With only these four pieces of data we will simulate depositing money, withdrawing money, and transferring money to another account. The withdraw function should only work if the bank account has enough money to withdraw a requested amount. The transfer function carries a $2 fee given that the account has enough money to transfer out and the balance is less than $10,000. Otherwise, the app will warn the user about the error information.

For this project, I will assume that you are using the NetBeans IDE and that you are familiar with object-oriented programming concepts. Also, that you can create a from using NetBeans’ GUI Builder. I will also assume that you are comfortable reading from and writing to files using java reader and writer APIs.

 


Using the following (<>) delimited data.

1231<>2012/2/3<>Jack Williams<>168.0

1232<>2012/2/3<>Lily Makki<>532.89

1233<>2012/2/4<>Peter Hansen<>58.10

1234<>2012/2/4<>Cathy Johns<>750.04

1235<>2012/2/4<>Paul Davis<>946.11

1236<>2012/2/5<>Michael Lopez<>223.06

1237<>2012/2/5<>John Anderson<>597.21

1238<>2012/2/5<>Ming Chen<>259.04

1239<>2012/2/5<>Sijun Zhang<>623.12

The first column contains the account number

The second column contains the account open date

The third column contains the account holder’s name

The fourth column contains the account’s balance

For this project, we will create five classes named:

            AccountApp, AccountUtility, AccountContants, Account, ChechingAccount

AccountApp class: This class contains the code for the jform that will serve as the gui for the app. Also, it is the manager of the app calling the necessary methods as the app deems necessary.

AccountUtility class: This class will be where most of the work is done for the app. Including reading the file, writing to file as you modify the account balance, as well as create accounts that will contain data as long as the app is running and used to retrieve data to be written to the file.

AccountConstants class: This class will only contain two constants and will be extended by the Account class, there the constants will be used to check if conditions are met in the accounts.

Account class: This class will define the characteristics of every account you create while working with the app. For instance, every account will have number, date, name, and balance. These variables will also need get and set methods to access the instance variables from outside the account class.

CheckingAccount: This class extends the Account class and contains the code to transfer money between accounts.

Now that we have an idea of what it should look like, we can start building the app.

  1. Open Netbeans and create each of the five classes listed above.
  2. Following the example on Figure-1 create a jform in the AccountApp class and add the necessary buttons and text fields. Remember to give your buttons and text field meaningful names, this will make it easier to add code to it later. ie… exitButton
  3. Easy peasy part here code your exit button to close the app.
  4. Work with your Account class,
    1. Create the instance variables listed above.
      1. String number
      2. String name
      3. GregorianCalendar date
      4. Double balance
    2. Create a constructor that takes two strings, a date, and a double and set those to the instance variables in the Account class.
    3. Create a get method that returns each of the four instance variables for the class.
    4. Create a set method that sets a given input to the instance variable of the Account.
    5. Create a method that takes a double as an input and adds it to the balance of the current account.
    6. Create a method that takes a double as an input and subtracts it to the balance of the current account, return true if the transaction completes.
  5. Work with the AccountConstants class: Here create two constants to be used in the app to subtract a transfer fee and check threshold of checking accounts.
  6. Work with CheckingAccount:
    1. Remember to extend the Account class
    2. Create a constructor similar to that of Account class that uses the super keyword.
    3. Create a method that takes a double and a CheckingAccount that will subtract that double amount from the current account and adds it to the given account. Be sure that your logic checks that current account has enough to transfer, also checks if current account has more than threshold.
      1. Return 0 if transfer was completed without a transfer fee.
      2. Return 1 if transfer was completed with a transfer fee.
      3. Return -1 if transfer was not completed because balance is less than transfer amount and transfer fee.
      4. Return -2 if transfer was not completed because balance is less than transfer amount.
  7. Work with AccountUtility:
    1. This class will have two instance variables
      1. File with a relative file path that will have your data.
      2. A hash map that will take a String (account number) as a key and CheckingAccount as the value.
    2. Create a blank constructor for this class.
    3. Create a method that will read your file, creates a CheckingAccount for each line and store each account to the hash map with the account number as a key.
    4. Create a method that gets the text from the dropdown and returns the corresponding CheckingAccount.
    5. Create a method that takes a string as an argument and returns true if that string is a key in the hash map, in other words a CheckingAccount with that account number exist.
    6. Create a method that loops though each of the CheckingAccounts in the hash map and prints them to your file in the same format as our original file but with the new altered data.cap1Figure-2
  8. Work with AccountApp:
    1. First instantiate an instance of your AccountUtility class.
    2. Load the data from your file by running the method you created in AccountUtility.
    3. Loop though your hash map that contains the CheckingAccounts and print the number strings to the dropdown of the jform.
    4. Create a method that fills the form using the current CheckingAccount loaded on the dropdown.
  9. Still working with AccountApp but now each of the action buttons. For this section you will need to use jOptionPane to get additional user input and to output error messages. (ShowMessageDialog and ShowInputDialog)
    1. withdrawAction
      1. Get account number from dropdown.
      2. Ask user to enter a double amount to withdraw
      3. Withdraw if appropriate.
      4. Write to your file using the updated CheckingAccount information.
      5. Load data to your jfrom.
    2.   depositAction
      1. Get account number from dropdown
      2. Ask user to enter a double amount to deposit
      3. Deposit.
      4. Write to your file using the updated CheckingAccounts information.
      5. Load data to your jform.
    3. transferAction
      1. Get current account from dropdown
      2. Ask user for transfer amount
      3. Ask user for transfer account
      4. Complete transfer if appropriate.
      5. Display appropriate output message using the returned integer from the transfer method.
      6. Write to file using the updated CheckingAccount information.
      7. Load your data to the jfrom.cap2Figure-3

I am including a downloadable version of this app if you would like to try it out. Simply download from the link below and extract the folder.

http://natrivera.com/bank-app.zip

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s