I'm doing a rather convoluted project for a class regarding looping structures and have run into a novice-ish logic error that I can't figure out.
The error being that the following loop never ends:
//get transaction values and perform actions.
try
{
sentinalValue = Double.parseDouble(JOptionPane.showInputDialog
("Enter transaction now. Enter \"-1\" to " +
"end transaction group."));
}
catch(java.lang.NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Only numeric values may be" +
" entered. A value of 0 is assumed.");
}
catch(java.lang.NullPointerException e)
{
//soft exit on cancel.
System.exit(0);
}
while(sentinalValue != -1.0)
{
if(isDeposit == true)
{
totalTransaction = totalTransaction + sentinalValue;
balance = balance + sentinalValue;
}
else
{
totalTransaction = totalTransaction - sentinalValue;
balance = balance - sentinalValue;
}
try
{
sentinalValue = Double.parseDouble(JOptionPane.showInputDialog
("Enter transaction now. Enter \"-1\" to " +
"end transaction group."));
}
catch(java.lang.NumberFormatException e)
{
JOptionPane.showMessageDialog(null, "Only numeric values may be" +
" entered. A value of 0 is assumed.");
}
catch(java.lang.NullPointerException e)
{
//soft exit on cancel.
System.exit(0);
}
//debugging line
System.out.println(sentinalValue);
}
I have the feeling it's a stupid mistake I made due in part to my inexperience with this language, but any help (or even simple advice) would be appreciated.