Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in Java that will figure out the required change for a purchase. Start by asking the user for the price of the

Write a program in Java that will figure out the required change for a purchase. Start by asking the user for the price of the product and the amount paid. (We are expecting that the user will give a larger value for the amount paid.) Read in each of these values as a double. Report back to the user the number of each denomination of change due. You are not just telling the user the amount of money he gets back.

Hint: Working with integers is much easier. The modulo operator is your friend for this assignment. Also, note that pennies can be tricky due to the poor real number to binary conversions. (Remember that 1.00 could actually be stored as 0.9999999999997.)

Do not include five-dollar bills, ten-dollar bills, etc. Only show coins and one-dollar bill amounts. Be sure to test multiple values.

There is a test case below. Your program should run the test case exactly as it appears below, and should work on any other case in general.

Output Example (User input is marked with >>>. Everything else is what you print to the screen.)

Welcome to my Change Maker. I will help you make change.

Please enter the cost of the product:

>>> 34.82

Please enter the amount paid:

>>> 40.00

Your change is $5.18.

You will get back:

5 one-dollar bills

0 quarters

1 dimes

1 nickels

3 pennies

Thank you for your business!

Below is what I have so far. The one thing I am having trouble is with the pennies.image text in transcribed

Projects > ChangeWW.java > &$ ChangeWW > main(Stringa) import java.util.*; 7 import java.text.DecimalFormat; 6 SRS 9 class ChangeWW { Run Debug public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double cost; double paid; int ones; int pennies, nickels, dimes, quarters; System.out.println("Welcome to my Change Maker. I will help you make change."); System.out.println("Please enter the cost of the product: "); cost = scanner.nextDouble(); System.out.println("Please enter the amount paid: "); paid = scanner.nextDouble(); 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 double change = paid - cost; DecimalFormat df1 = new DecimalFormat("0.00"); System.out.println("Your change is $" + df1.format(change) + "."); System.out.println("You will not hack. ". double change - ChangeWw.main(String[]) ones = (int) Math.round(change); change = change % 1; quarters = (int) (change / 0.25); change = change % .25; dimes = (int) (change / 0.10); change = change % .10; nickels = (int) (change / 0.05); change = change % .05; 40 pennies = (int) (change / 0.01); change = change % .01; + ones + 41 42 43 44 45 46 47 48 49 50 51 52 53 System.out.println(" one-dollar bills"); System.out.println(" " + quarters + " quarters"); System.out.println(" + dimes + dimes"); System.out.println(" + nickels + " nickels"); System.out.println(" + pennies + " pennies"); System.out.println("Thank you for your business!"); } }

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago