Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago

Question

Discuss the key ambient conditions and their effects on customers.

Answered: 1 week ago