| | |
Help with my code....
![]() |
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
actually,,this is not my whole code..i just post the important one,,i am having problem with my code....i dont know how to figure out,,,
everytime i am trying to withdraw and deposit..,,the balance will always be zero,, and i dont know how to figure it out....
everytime i am trying to withdraw and deposit..,,the balance will always be zero,, and i dont know how to figure it out....
Java Syntax (Toggle Plain Text)
import javax.swing.*; public class BankAccount{ String deposit = ""; String withdraw = ""; int withdrawAmount; float depositAmount; float balance = (float) 0.0; float newBalance; ATM atm = new ATM(); public void depositCash(){ try{ deposit = JOptionPane.showInputDialog(null,"How much you want to deposit?"); depositAmount = Float.parseFloat(deposit); newBalance = newBalance +depositAmount; JOptionPane.showMessageDialog(null, "You have deposit an amount of :\nP"+depositAmount); atm.optionList(); }catch(Exception e){ JOptionPane.showMessageDialog(null,"Invalid input"); depositCash(); } } public boolean withdrawCash(){ do{ try{ withdraw = JOptionPane.showInputDialog(null, "How much you want to withdraw?"); withdrawAmount = Integer.parseInt(withdraw); newBalance = balance - withdrawAmount; if (withdrawAmount>100){ JOptionPane.showMessageDialog(null, "You have withdraw for a total amount of:" + "\nP"+withdrawAmount); atm.optionList(); return withdrawCash(); } else if(withdrawAmount<100){ JOptionPane.showMessageDialog(null,"Invalid amount. Any withdrawal must be at least" + "P100.00.\nPlease try again."); continue; }else if(withdrawAmount>newBalance){ JOptionPane.showMessageDialog(null, "Sorry, you have insufficient balance to" + " withdraw the amount you want. Please check your balance first. Thank you."); continue; } }catch(Exception e){ JOptionPane.showMessageDialog(null, "invalid input."); continue; } }while(true); } public float getBalance(){ JOptionPane.showMessageDialog(null,"You have a balance of :\nP" +newBalance+"\nin your" + " savings account."); atm.optionList(); return newBalance; } }
Last edited by ~s.o.s~; Nov 17th, 2008 at 11:04 pm. Reason: Added code tags, learn to use them.
•
•
Join Date: Sep 2008
Posts: 1,571
Reputation:
Solved Threads: 196
float balance = (float) 0.0;
Saying (float) is unnecessary here, the compiler knows you are declaring a float.
The 'continue' statements are unnecessary, as far as I know, so you should consider that. (It isn't your problem, I don't think)
However, one way to limit down your problem is to add some print statements. For example, did you check to make sure you're reading in what the user entered correctly? That is a big step towards figuring out where your problem is. Try it and tell me what you get
Saying (float) is unnecessary here, the compiler knows you are declaring a float.
The 'continue' statements are unnecessary, as far as I know, so you should consider that. (It isn't your problem, I don't think)
However, one way to limit down your problem is to add some print statements. For example, did you check to make sure you're reading in what the user entered correctly? That is a big step towards figuring out where your problem is. Try it and tell me what you get
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the Java Forum
- Previous Thread: How many users checked a link in 15 mins?
- Next Thread: repositioning buttons!!
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






