Question
Write a program that will prompt the user for a purchase amount. If this bill amount is valid, then prompt the user again for the
Write a program that will prompt the user for a purchase amount. If this bill amount is valid, then prompt the user again for the payment amount. If this is valid then compute the change to be returned. This amount should be displayed in pennies, nickels, dimes, quarters, single dollar bills, five dollar bills, ten dollar bills, and 20 dollar bills. If either of the input values are invalid, an error message should be displayed explaining precisely where the error is.
Use java.util.Scanner as well as constants for each amount (20,10,5,1,0.25,0.1,0.05 and 0.01).
Thank you in advance!!
Sample run number 1: This program will compute the proper change from a purchase. Please enter the purchase amount: $1.32 Please enter the payment amount: $20 The change is : 1 TEN(S) 1 FIVE(S) 3 ONE(S) 2 QUARTER(S) 1 DIME(S) 1 NICKEL(S) 3 PENNIES Sample run number 2: This program will compute the proper change from a purchase. Please enter the purchase amount: $-1 The purchase amount has an error! The purchase amount must be at least 1 cent. Sample run number 3: This program will compute the proper change from a purchase. Please enter the purchase amount: $7.32 Please enter the payment amount: $5 The payment amount has an error. Payment amount must be at greater than or equal to the purchase amount
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