HI
i wrote a code to validate cash for a vending machine.... the problem am having is dat dat my code failed to validate any ammount.
please help!!!!
the code is below
public static double validDollarNote () {
boolean done = false;
double cash = 0.0;
String bill;
double Nickel = 0.05;
double Dime = 0.10;
double Quarter = 0.25;
double OneDollar = 1.0;
double FiveDollar = 5.0;
while (!done) {
bill = JOptionPane.sho wInputDialog("P ay:");
try {
cash = Double.parseDou ble(bill);
System.out.prin tln(cash);
if (cash != Dime || cash != Nickel || cash != Quarter || cash != OneDollar || cash != FiveDollar) {
throw new NumberFormatExc eption();
}
else
{
done = true;
}
} catch (NumberFormatEx ception e) {
JOptionPane.sho wMessageDialog( null, "MACHINE ACCEPTS: $.05,$.10,$.25, $1,$5\n",
"Error", JOptionPane.INF ORMATION_MESSAG E);
}
}
return cash;
}
i wrote a code to validate cash for a vending machine.... the problem am having is dat dat my code failed to validate any ammount.
please help!!!!
the code is below
public static double validDollarNote () {
boolean done = false;
double cash = 0.0;
String bill;
double Nickel = 0.05;
double Dime = 0.10;
double Quarter = 0.25;
double OneDollar = 1.0;
double FiveDollar = 5.0;
while (!done) {
bill = JOptionPane.sho wInputDialog("P ay:");
try {
cash = Double.parseDou ble(bill);
System.out.prin tln(cash);
if (cash != Dime || cash != Nickel || cash != Quarter || cash != OneDollar || cash != FiveDollar) {
throw new NumberFormatExc eption();
}
else
{
done = true;
}
} catch (NumberFormatEx ception e) {
JOptionPane.sho wMessageDialog( null, "MACHINE ACCEPTS: $.05,$.10,$.25, $1,$5\n",
"Error", JOptionPane.INF ORMATION_MESSAG E);
}
}
return cash;
}
Comment