This is my Complete bank account program.
import javax.swing.JOptionPane; public class BankAcct {// start of class private String clientName; private double BankMoney; private double Transaction; double kth; private String png; private String ptr; public String Getclientname(){ return clientName; } public double GetBankMoney(){ return BankMoney; } public double GetTransaction(){ return Transaction; } public String Getpng(){ return png; } public String Getptr(){ return ptr; } public void SetclientName(String clientName){ this.clientName = clientName; } public void SetBankMoney(double BankMoney){ this.BankMoney = BankMoney; } public void SetTransaction(double Transaction){ this.Transaction = Transaction; } public void Setpng(String png){ this.png = png; } public void Setptr(String ptr){ this.ptr = ptr; } public static void main(String[] args){// start of main BankAcct inf = new BankAcct(); String ft,wh = ""; inf.Setpng(JOptionPane.showInputDialog("Do you want to create a bank account[Yes][No]")); do{ //Start of outer do if("Yes".equalsIgnoreCase(inf.png)) { // start of if inf.SetclientName(JOptionPane.showInputDialog("Enter your Name: ")); ft =JOptionPane.showInputDialog("Enter your account Number: "); inf.BankMoney = Double.parseDouble(JOptionPane.showInputDialog("Enter the money to put into your bank account")); inf.kth=Double.parseDouble(JOptionPane.showInputDialog(null,"your account Name: "+inf.clientName +"\nAccount Number: ***** " + "\n Your Balance: "+inf.BankMoney+"\nPress[1]" +"to Withdraw \nPress[2] to Deposit \nPress [3] to Exit")); } // end of if else return; switch((int)inf.kth) { //start of switch case 1: double db; double bd; do{ //start of inner do db =Double.parseDouble(JOptionPane.showInputDialog("Enter the money to Withdraw: ")); bd = inf.BankMoney -db ; if(bd<0){//start of if inf.ptr=JOptionPane.showInputDialog("Overwithdrawing!!Try Again?[yes][no]"); }//end of if else if("NO".equalsIgnoreCase(inf.ptr))return; else JOptionPane.showMessageDialog(null,"Starting Money: "+inf.BankMoney+"\nMoney Withdraw: "+db+"\nCurrent Savings: " + bd); } //end of inner do while("Yes".equalsIgnoreCase(inf.ptr)); break; case 2: double bb; double cv; bb =Double.parseDouble(JOptionPane.showInputDialog("Enter the money to deposit: ")); cv = bb + inf.BankMoney; JOptionPane.showMessageDialog(null,"Starting Money: "+inf.BankMoney+"\nMoney deposited: "+ bb+"\ncurrent Savings: "+ cv); break; case 3: JOptionPane.showMessageDialog(null, "Exiting! Thank your for using our program"); break; default: wh=JOptionPane.showInputDialog("Sorry Wrong Number!Try Again?[yes][no]"); }// end of switch } //end of outer do while("Yes".equalsIgnoreCase(wh)); }// end of class }//end of main
Im having error on this part
switch((int)inf.kth){ case 1: double db; double bd; do{ db =Double.parseDouble(JOptionPane.showInputDialog("Enter the money to Withdraw: ")); bd = inf.BankMoney -db ; if(bd<0) inf.ptr=JOptionPane.showInputDialog("Overwithdrawing!!Try Again[yes][no]"); else if("NO".equalsIgnoreCase(inf.ptr))return; else JOptionPane.showMessageDialog(null,"Starting Money: "+inf.BankMoney+"\nMoney Withdraw: "+db+"\nCurrent Savings: " + bd); } while("Yes".equalsIgnoreCase(inf.ptr)); break;
can someone tell me what s wrong in this code??? when i run my bank account program and trigger the overwithdrawing and type yes it loops and loops even i don't overdraw(means bd>=0). please help me to solve this problem.