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....
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;
}
}