import javax.swing.*; // import the swing library for I/O class change { public static void main (String[] param) { changedue(); System.exit(0); } // END main public static void changedue() { String textinput; String textinput1; String value1; int sale = 0; int amount = 0; int chnge = 0; int f, twenty, ten, five, one; int price; int cost = 0; int change1; f = 0; twenty = 0; ten = 0; five = 0; one = 0; { textinput = JOptionPane.showInputDialog("Please enter the amount of the sale"); cost = Integer.parseInt(textinput); textinput1 = JOptionPane.showInputDialog(null, "Please enter the amount the customer paid in"); price = Integer.parseInt(textinput1); change1 = (price - cost) * 100; System.out.println(change1); if (change1 >= 50) { f = change1 / 50; double d = Math.floor(f); change1 = change1 - (f * 50); } while (change1 >= 20) { twenty = change1 / 20; double d = Math.floor(twenty); change1 = change1 - (twenty * 20); } while (change1 >= 10) { ten = change1 / 10; double d = Math.floor(ten); change1 = change1 - (ten * 10); } while (change1 >= 5) { five = change1 / 5; double d = Math.floor(five); change1 = change1 - (five * 5); } while (change1 >= 1) { one = change1 / 1; double d = Math.floor(one); change1 = change1 - (one * 1); } System.out.println("number of one penny's" + one); System.out.println("number of five penny's" + five); System.out.println("number of ten penny's" + ten); System.out.println("number of twenty penny's" + twenty); System.out.println("number of fifty penny's" + f); } } // END changedue } // END class change
I get this error whenever I input a decimal number like 9.50, why? how can i stop this :S
Terminal spits out this when i do
Exception in thread "main" java.lang.NumberFormatException: For input string: "9.50"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at change.changedue(change.java:36)
at change.main(change.java:9)