Search This Blog
Your code mix the business concerns with the infrastructure, reading from the command line has nothing do to in the same class as the one that manage an account. You should have a look at some commons patterns like MVC. I would have introduced one AccountsService with one method for each use case: This service will be used to isolate the business logic. Mine will be a simple class with a main loop.
Separation of concerns
The first step would be to select or create a account, then all actions will be done on this account, like an ATM. I like to do a development that is close to DDD ; I would have introduced one Account which can be retrieve or saved from an AccountsRepository.
This Account would have one method for each use case with some pre-conditions:. You see that there is a direct match between the methods from Account and AccountsService. The service will just enforce the preconditions by validating the inputs and delegate to the methods on Account. This is where you do the link between the infrastructure and business repository is infrastructure but later you maye also add security, transactions, logging,..
Notice that I use a conventions that use verbs for method that changes the system but looks like getters when querying the state. You may not like this conventions but the idea is to highlight the importance of conventions and self documented code.
The first idea that I had in mind was to manage one mutable BigDecimal field. It works well for the basis of deposit: But then when you have to deal with the daily limit, things are more complex. You may hold a date and a sum of daily withdraw but another way is to maintains a List of Operation that have a time and an amount, deposit will add a new Operation amount while withdraw add one new Operation amount.
To compute the daily withdraw, you have to filter all the operations for the current day that are withdraw amount is negative and sum them.
The balance is computed by reducing all the operations via an addition. By separating everything you can easily test the behaviors of Account and interactions of AccountsService. The only things that is complex to test is your BakingApplicationCli. You can find my solution on https: I have also added one AccountFactory to create a new valid Account. This one does not do many thing but may evolve in time and isolate the creation process. I have chosen to add a getDailyLimit method in Account so that we can imagine to have on abstract Account and many implementations with different limits.
The factory is then the perfect place to choose the implementation.
- Bank Application in Java - Simulation of Banking Services in Java | Java Tongue!
- download nokia x2 default ringtone;
- whatsapp ios to android migration.
- kjv bible free download for mobile application.
The awareness of concurrency which can corrupt non-atomic transactions. As double s are imprecise, better use BigDecimal: However as there are several things other people already mentioned, I leave it to that.
For a fast improvement:. My two cents. So the intention I understand was to create a Bank Application with certain banking actions. What I feel is that, that code you have shared is not an application but a program which can do the banking actions mentioned.
Bank app in Java - Code Review Stack Exchange
One way to see it was to start thinking from an End Users perspective. Since it will be the simplest alternative. Then the next would be the architectural design of your application. The banking actions mentioned in the above question are your "Domain". The Domain's requirments needed to be encapsulated from the rest of the world. There need to be Unit Tests coverage as well for the Services that you would create.
- Your Answer!
- My version.
- samsung galaxy s4 mini flip cover review;
Bank app in Java Ask Question. Timothy Truckle 4, 4 Emerson Fonseca Emerson Fonseca 11 1. My version Following is my version of your bank account class, with the members removed that I think should not be part of the account class. So instead of: Also consider a double datatype. Tanvi Jaywant Tanvi Jaywant 2. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.
Java program for banking management system
The cash withdrawal can be done through QR or …. Java Updated Jun 11, A Distributed banking application that supports chandy lamport snapshot algorithm. Java Updated Jul 25, Java Updated Feb 19, Implementation of Distributed bank having multiple branches. The controller in bank uses Chandy-Lamport global snapsh….