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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.