Question
my code is below i cant seem to get it working corretly Exception in thread main java.lang.NumberFormatException: For input string: 1.93 at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68) at java.base/java.lang.Integer.parseInt(Integer.java:658)
my code is below i cant seem to get it working corretly Exception in thread "main" java.lang.NumberFormatException: For input string: "1.93" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68) at java.base/java.lang.Integer.parseInt(Integer.java:658) at java.base/java.lang.Integer.parseInt(Integer.java:776) at Change.main(Change.java:41) Thats my error
// Change Class with Double import java.util.*; public class Change { static double amount,price; public static void main(String[] args) { // Starting with a friendly message System.out.println("----------- Welcome to Change project -----------"); String exit =""; while(!exit.equals( "-1")) // While the user want to restart a new simulation we will not get out from the loop { // Asking the product's price System.out.println("Please give us the product's price : "); Scanner priceReader = new Scanner(System.in); // Create a Scanner price reader variable to read the user's price input String priceS = priceReader.nextLine(); // Read user's price string input boolean validPrice = false; try { price = Double.parseDouble(priceS); validPrice = true; } catch (NumberFormatException e) { System.out.println("Please give a valid price !!!"); } if(validPrice) { System.out.println("Please give us the amount tendered : "); Scanner amountReader = new Scanner(System.in); // Create a Scanner amount reader variable to read the user's amount input String amountS = priceReader.nextLine(); // Read user's amount string input boolean validAmount = false; try { amount = Double.parseDouble(amountS); validAmount = true; } catch (NumberFormatException e) { System.out.println("Please give a valid amount !!!"); } if(validAmount) { Double rest = amount- price ; // We calculate the difference between amount and price if(rest >= 0 ) { System.out.println(" Your change is: "+rest); double dollars = Integer.parseInt(rest.toString()); rest = rest- dollars; rest = rest*10; double dime = Integer.parseInt(rest.toString()); rest = rest-dime; rest = rest*10; Double intermediate = rest/5; int nickel = Integer.parseInt(intermediate.toString()); rest = rest-nickel*5; double penny = Integer.parseInt(rest.toString()); System.out.println(dollars + " one-dollar bills "); System.out.println("0 quarters "); System.out.println(dime + " dimes "); System.out.println(nickel + " nickels "); System.out.println(penny + " pennies "); } else { System.out.println("Please check your entries "); } } System.out.println("Please tape -1 if you want to exit"); Scanner exitReader = new Scanner(System.in); // Create a Scanner to read user's choice exit = exitReader.nextLine(); } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started