QuestionQuestion

Write a program that accepts the price for an item, amount of payment, and computes the change required to repay a customer. Any purchase less than $10 incurs a surcharge of 10% of the purchase price.

Requirements:
• The name of the class that contains the main method must be CashRegister.
• Constants must be defined and used for the tax rate (7%) and the maximum price ($250) and surcharge rate of (10%).
• Output of all dollar amounts (other than dollar-bill/coin denominations) will be of the form $X.XX (U.S. currency format). You must use the System.out.printf() method to format the output of bill and coin amounts.
• The program will quit when the user enters zero or a negative number.
• The program will loop until a valid purchase price is entered (0 < price ≤ 250).
• Any purchase price less than $10 must have a 10% surcharge added to the total amount due but calculated on the purchase price. (see session 1)
• The user must present enough money to pay for the total purchase with a single amount. If the user enters and amount too small to cover the purchase the use must be again asked for a sufficient amount.
• The program will compute and output the most appropriate change given the amount of change that must be returned to the customer. That is, $5 should be returned as a single $5 bill and not five $1 bills; similarly, for coins.
• Your output must exactly match the sample output shown below for the same inputs.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.Scanner;

/*
* CashRegister class
*/
public class CashRegister {

/*
   * Program constants
   */
static final double TAX_RATE = 7;
static final double MAXIMUM_PRICE = 250;
static final double SURCHARGE_RATE = 10;

/*
   * Main method for program execution
   */
public static void main(String[] args) {
    // Construct Scanner object to read input
    Scanner readInput = new Scanner(System.in);
    // Run program in a loop
    while (true) {
      // Query the cost of the transaction
      System.out.printf("Cost of transaction (enter 0 or negative value to exit; max is $%.2f): ", MAXIMUM_PRICE);
      double cost = readInput.nextDouble();
      // If cost is not positive exit loop
      if (cost <= 0) {
       break;
      // If cost is greater than maximum skip to next iteration of loop
      } else if (cost > MAXIMUM_PRICE) {
       continue;
      }
      // Define surcharge...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$45.00 $22.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats