• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bank Account Project  RSS feed

 
Raj Khaira
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, this is my first time posting on this forum and I'm very excited to do so!

So my question is: I am working on a project to make a simple working bank account system with three main features; withdraw, deposit, and view balance. Obviously as any bank account "balance" is the main focus here. Because everything is based around it. I'm having an issue where, for example when a user deposits a certain amount into his/her bank account the balance should change, which it does! But when I compile and run the program to perform another function my balance variable resets to zero. Why does it keep resetting to zero? and how can I store the users values without them disappearing? (Note: I have just very recently started coding and am nowhere near to being a pro!) Thanks for the help!

CODE:







 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean the balance resets when you try to do something else besides deposits? Such as withdraw and view?
 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj Khaira wrote:when I compile and run the program to perform another function my balance variable resets to zero. Why does it keep resetting to zero? and how can I store the users values without them disappearing?

Welcome to the Ranch!

Your program resides in the computer's memory and only "lives" while it is up and running. Once your program exits, it is purged from memory along with all the values of variables that you set while the program was running. That is, upon exiting, the program and all the information that it was "remembering" disappears and is essentially forgotten. When you run the program again, everything goes back to a pristine "brand new" state and you will have to do everything over again. If you want your program to "remember" its state from a previous run, you will have to persist (save) that state to a place where it won't disappear after the program terminates. Later on, when you run your program again, you will have to read the previously saved state and restore those values back in your program. 

There are many options available to you for persisting your program's state. For simple programs with very limited state information, you can use plain old text files (properties files, XML files, JSON files, CSV files, etc.)  For more sophisticated applications, you can use a database system like MySQL. Whatever option you end up choosing, there are many tasks that you will have to program into your application so that it can properly manage the information going into and out of persistent storage.

Given that the code you showed is very primitive -- you have everything in the static main() method -- I would have to honestly say that you're not in any position right now to even start thinking about saving your program's state in persistent storage.  My advice would be to first learn how to partition your program's many different parts into more manageable pieces by creating proper classes with fields and methods.  Right now, what you have is basically a "script" that will soon become an ugly, unwieldy mess if you keep going the way that you've been going so far.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:. . . you're not in any position right now to even start thinking about saving your program's state . . .
I would go even further and say that because there are no objects with fields, that program doesn't have any state to save. I would suggest you have a Bank class and Account class as a minimum.

And welcome again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!