Simple Banking Applications with Java

Hello fellow daoist,

Yesterday, I’m learning java by doing simple project named Banking Applications, it is not using any database, just a simple console that emulates the banking work flow.

Now, I want to share on how you can make one too. I assume that you already at level where you can create new project for java. So I will bypass any formality and just explain on the code.

First, you may want to create new project for java application ( I’m using Intellij IDEA IDE ), I named my project BankingApplications.

When you created the new project, you will get a new blank that looks like this.

Next, add a new class after the public class Main, let’s call it BankAccount, in the class you need variable like : balance, previous transaction, account name, and account id.

Of course in a bank application there’s always work like deposit and withdraw money from the bank, that is why inside the BankAccount class insert the deposit and withdraw method.

Don’t forget that deposit will increase your balance, while withdraw will decrease your balance. Also that for the previous transaction to know whether you deposit or withdraw too.

In the above code, using the BankAccount method means that when I declared on new BankAccount class, I will need to insert parameters “name” and “id”. As you can see too, the parameter will be copied to variable accountName and accountId.

The 3 method beside BankAccount was “deposit”, “withdraw”, and “getPreviousTransaction” and they will be used to deposit money, withdraw money, and see what kind of transaction before.

Like I just said, when deposit money, your balance will increase with the amount of money deposited, and decrease with the amount withdrawn.

In the getPreviousTransaction method that we used, to difference on whether deposit or withdraw were executed, we just need to fill the variable previousTransaction with either a positif, a negatif, or just 0.

Positif means deposit, Negatif means withdraw, and 0 means there is no transaction ever occur.

Next, we will need to bring up the menu of the banking application, in banking application you will need (for now) 5 menus.

a. check balance
b. deposit
c. withdraw
d. check previous transaction
e. exit program

Before we make menus, you will need input from player, the input can be obtained by using Scanner in java. The Scanner will process the input, and you can get it to check what input the user type.

As you see on the showMenu method, we used a loop with while and switch to filter what kind of response needed to show to the user.

To make this banking application to run and show it menus all you need is to create new object of BankAccount and call the showMenu method like below in the public static void main.

Of course, now you can run the code and simply test the banking application is working or not. But this code is still prone of errors and that is why we will fix some of the errors.

The 2 main errors in this code is, first the option input from user to choose which menu will be run. Char is different to string, therefor ‘A’ is not the same as ‘a’, so if the user inputs an ‘A’ , then it will not run the ‘a’.

The fix is using the Character function to lower case the Char variable.

The second one is when you’re require to insert the amount to deposit or withdraw, any words beside number will be causing errors, that is why we will use a little loop on to check if the input is number (integer) or not.

The “hasNextInt” in java will check whether the input is number (integer) or not, and while it is not, then it will return to before and request another input from the user.

Ps: The same thing will be needed to apply on the withdraw.

So, how about it? Do you understand a little about this simple banking application? If you had any questions about this please leave it in the comment sections.

Note: Full code will be up to github when I had the time, cheers 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *