Support computing sales tax in the CashRegister class. The tax rate should be supplied when constructing a CashRegister object. Add recordTaxablePurchase and getTotalTax methods. (Amounts added with recordPurchase are not taxable.) The giveChange method should correctly reflect the sales tax that is charged on taxable items. Please add the method to the CashRegisterTester. The input and output are also provided below. CashRegister class: import java.util.Scanner; public class CashRegister { private double purchase; private double payment; /** Constructs a cash register with no money in it. */ public CashRegister() { purchase = 0; payment = 0; } /** Records the sale of an item. @param amount the price of the item */ public void recordPurchase(double amount) { purchase = purchase + amount; } /** Processes a payment received from the customer. @param amount the amount of the payment */ public void receivePayment(double amount) { payment = payment + amount; } /** Computes the change due and resets the machine for the next customer. @return the change due to the customer */ public double giveChange() { double change = payment - purchase; purchase = 0; payment = 0; return change; } //add method to print the receipt public void printReceipt(){ System.out.println("Please enter each of the five items you have bought and their prices(the names of the items shouldn't contain any spaces):"); Scanner input = new Scanner(System.in); int count = 0; double totalAmount = 0; String items = ""; String prices = ""; while (count < 5){ //get the item and its price from the customer String item = input.next(); double price = input.nextDouble(); totalAmount += price; //concat all items and prices items = items.concat(item).concat(" "); prices = prices.concat(String.valueOf(price)).concat(" "); count++; } System.out.println(items); System.out.println(prices); System.out.println(totalAmount); } }
Java programming please
Support computing sales tax in the CashRegister class. The tax rate should be supplied when constructing a CashRegister object. Add recordTaxablePurchase and getTotalTax methods. (Amounts added with recordPurchase are not taxable.) The giveChange method should correctly reflect the sales tax that is charged on taxable items. Please add the method to the CashRegisterTester. The input and output are also provided below.
CashRegister class:
import java.util.Scanner;
public class CashRegister {
private double purchase;
private double payment;
/**
Constructs a cash register with no money in it.
*/
public CashRegister()
{
purchase = 0;
payment = 0;
}
/**
Records the sale of an item.
@param amount the price of the item
*/
public void recordPurchase(double amount)
{
purchase = purchase + amount;
}
/**
Processes a payment received from the customer.
@param amount the amount of the payment
*/
public void receivePayment(double amount)
{
payment = payment + amount;
}
/**
Computes the change due and resets the machine for the next customer.
@return the change due to the customer
*/
public double giveChange()
{
double change = payment - purchase;
purchase = 0;
payment = 0;
return change;
}
//add method to print the receipt
public void printReceipt(){
System.out.println("Please enter each of the five items you have bought and their prices(the names of the items shouldn't contain any spaces):");
Scanner input = new Scanner(System.in);
int count = 0;
double totalAmount = 0;
String items = "";
String prices = "";
while (count < 5){
//get the item and its price from the customer
String item = input.next();
double price = input.nextDouble();
totalAmount += price;
//concat all items and prices
items = items.concat(item).concat(" ");
prices = prices.concat(String.valueOf(price)).concat(" ");
count++;
}
System.out.println(items);
System.out.println(prices);
System.out.println(totalAmount);
}
}
Input and Output: (see image attached)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps