• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bank Account Program Help

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a new programmer, and I need a program to start me off that can do the following:

1. Get the following input from the user:
a) Beginning bank account balance
b) Ask whether they are depositing or withdrawing
c) Then ask the amount of the deposit or withdrawal

2. It should also keep track of the balance and print the balance out to the screen after every transaction


Thanks to those ahead of time that are willing to help me!

[ August 17, 2005: Message edited by: Victor Knyt ]
[JAM -- I edited the title so that people are less likely to ignore it]
[ August 17, 2005: Message edited by: Joel McNary ]
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nobody is going to write your program for you.
If you show us how you would like to implement it (in pseudo code or something similar) then people here will point you in the right direction for what you need to know to implement it in Java.

Just as an aside, are you sure 1a is a correct requirement ? Bank machines usually know what your balance is.
 
Victor Knyt
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, but this is a simple program, so for the bank balance I'm going to need to ask the user to enter it in.

And this is what I have so far (I know there is still a lot more to be added):

import java.io.*;
import javax.swing.JOptionPane;

public class Bank
{
public static void main (String args[])
{
float money;

JOptionPane.showInputDialog(null, "Please enter your bank account balance:");

JOptionPane.showInputDialog(null, "Are you depositing or withdrawing?");

JOptionPane.showInputDialog(null, "How much would you like to deposit?");

JOptionPane.showInputDialog(null, "How much would you like to withdrawa?");

/*I know that somewhere in the above statement you need to have a If and Then statement
that way you know if they chose to withdraw, then the "How much would you like to withdrawa?" box will pop up
or deposit, based on what they have chosen*/
}
}
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JOptionPane.showInputDialog returns a String containing whatever the user typed in, so you have to assign this value to a variable.
e.g.

You will then need to convert this String to a float or double. See the API docs for the Float and Double classes for ways to do this.

Repeat this for the deposit and withdrawal amounts.

For the dialog asking whether the user wants to deposit or withdraw, you are probably better off using JOptionPane.showOptionDialog() method, but if you want to stick with showInputDialog, you will need to compare the value returned.


Have a play around with these and if you have any problems, post your new code.
 
Victor Knyt
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the help! I'm completely lost, so basically I am gonna try to "parse" the questions, and if that doesn't work I'll just call it quits.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't give up. Your first post gave the impression that you were just expecting people to do your homework for you. That's probably why you didn't get many answers.
Your later posts show you you have done some work, so I think you'll find folk on here will be happy to help you. Post your new code and I'm sure you'll get plenty of helpful suggestions.
 
Victor Knyt
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this is what I have so far...any help is appreciated.

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay.
returns a double value, so you need to assign it to a variable.Note, that this can throw a NumberFormatException if what the user entered is not a valid floating point number, so you will need to put this in a try...catch statement.

Assign the values returned from your "how much would you like to deposit/withdraw" dialogs into a variable as I showed you before and convert them to doubles as shown above.

You can then use these values to do calculation e.g.and you can use System.out.println() to output text to the screen.

Let me know how you get on or if you have any problems.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joanne Neal:
Note, that this can throw a NumberFormatException if what the user entered is not a valid floating point number, so you will need to put this in a try...catch statement.



Sorry. NumberFormatException is an unchecked exception, so if you haven't looked at try...catch statements yet, ignore this part. Just make sure that anything you type in is a legal floating point number.
 
Victor Knyt
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joanne Neal, thank you very much for all your help and such quick replies, I'm gonna leave it at what I have (with your corrections ofcourse).

Thanks once more.
[ August 17, 2005: Message edited by: Victor Knyt ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to go off on a wild tangent for a bit on a neat way to solve problems. Given a problem like this, it's sometimes cool to work it from the inside out. The real guts of this thing keeps account balances. What if you start by writing this, and then make an Account class that makes it say "true" ...

That should take only a minute. Then you can quickly add these:

In a matter of minutes you can have a very small amount of running, tested code. With confidence that this works, you can build up the bit that translates "100.00" and "deposit" strings into 100.00D and calls the deposit method. Then build up the GUI that gets those values from the user.

Now for this problem you've already gotten past most of this stuff so it's kinda too late. For the next assignment, search for the smallest, simplest thing you could build and test. See if that sounds like a fun approach.

BTW: I used doubles here. They are lousy for money. Any amounts with pennies would likely fail the tests. But that's another topic.
[ August 17, 2005: Message edited by: Stan James ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are building up a project in stages like this, it is probably worth looking into the concept of unit testing as well. It will probably seem a bit complex at first and maybe a bit of an overkill for small projects, but once you have a good grasp of Java and you are starting to work on bigger projects, its benefits can be enormous.
Test Infected provides a good introduction.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right on, Joanne. I avoided mentioning JUnit because as much as I love it, I spent a whole day getting my head around making it work the first time. Take a look at that link, Victor. If you can digest it quickly, go for it. JUnit is good stuff fer sure.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic