I'm trying to write code which will validate the withdrawal amount. For instance, if the withdrawal amount is greater than the balance, an error should appear and say, "invalid withdrawal amount" but the problem is when I enter a invalid amount, an error message pops up. I try to enter a valid amount and it won't accept anything! It won't even let me close out the dialog box. How can I resolve this?
if (transactionChar== 'W' || transactionChar == 'w')
{
input = JOptionPane.showInputDialog("Please enter withdrawal amount.");
transactionAmount = Double.parseDouble(input);
while(transactionAmount >= oldBalance)
input = JOptionPane.showInputDialog("Invalid withdrawal amount. Please enter valid withdrawal amount!");
transactionAmount = Double.parseDouble(input);
newBalance = oldBalance - transactionAmount;
}
My declarations are
double oldBalance= 0; //Holds the value of the old balance
String transactionType= ""; //Holds the value of the transaction type.
char transactionChar ; //Gets input for either withdrawal or deposit
double transactionAmount= 0;