Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#8 Cash Register Class page 440-441 CashRegister Class Write a CashRegister class that can be used with the RetailItem class that you wrote in Chapter

#8 Cash Register Class

page 440-441

CashRegister Class

Write a CashRegister class that can be used with the RetailItem class that you wrote in Chapter 6s Programming Challenge 7. The CashRegister class should simulate the sale of a retail item. It should have a constructor that accepts a RetailItem object as an argument. The constructor should also accept an integer that represents the quantity of items being purchased. In addition, the class should have the following methods:

The getSubtotal method should return the subtotal of the sale, which is the quantity multiplied by the price. This method must get the price from the RetailItem object that was passed as an argument to the constructor.

The getTax method should return the amount of sales tax on the purchase. The sales tax rate is 6 percent of a retail sale.

The getTotal method should return the total of the sale, which is the subtotal plus the sales tax.

Demonstrate the class in a program that asks the user for the quantity of items being purchased, and then displays the sales subtotal, amount of sales tax, and total.

This program must be written using this UML

image text in transcribed

image text in transcribed

Here's my CashRegisterDemo

import java.util.Scanner; import java.text.DecimalFormat;

/** * Chapter 6 * Programming Challenge 8: CashRegister Class * This program demonstrates the CashRegister class. */

public class CashRegisterDemo { public static void main(String[] args) { int quantity; // Quantity being purchased

System.out.println("yourName today's date "); // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Create a RetailItem object. RetailItem item = new RetailItem("Candy bar", 17789, 0.75, 1.5); // Get the quantity. System.out.print("How many candy bars are you buying? "); quantity = keyboard.nextInt(); // Create a CashRegister object. CashRegister reg = new CashRegister(item, quantity); // Create a DecimalFormat object. DecimalFormat dollar = new DecimalFormat("#,##0.00"); // Display the sales data. System.out.println("Subtotal : $" + dollar.format(reg.getSubtotal())); System.out.println("Sales tax : $" + dollar.format(reg.getTax())); System.out.println("Total : $" + dollar.format(reg.getTotal())); } }

Heres my RetailItem class

import java.text.DecimalFormat; /** * Chapter 6 * Programming Challenge 7: RetailItem Class Modification * This version of the RetailItem class contains * accessor and mutator methods for getting and setting * an item's wholesale and retail cost. */ public class RetailItem { private String description; // Item description private int itemNumber; // Item number private CostData cost; // Cost data /** * RetailItem class constructor */ public RetailItem(String desc, int itemNum, double wholesale, double retail) { description = desc; itemNumber = itemNum; cost = new CostData(wholesale, retail); } /** * setWholesale method */ public void setWholesale(double w) { cost.wholesale = w; } /** * setRetail method */ public void setRetail(double r) { cost.retail = r; } /** * getWholesale method */ public double getWholesale() { return cost.wholesale; } /** * getRetail method */ public double getRetail() { return cost.retail; } /** * RetailItem class toString method */ public String toString() { String str; DecimalFormat dollar = new DecimalFormat("#,##0.00"); str = "Description: " + description + " Item Number: " + itemNumber + " Wholesale Cost: $" + dollar.format(cost.wholesale) + " Retail Price: $" + dollar.format(cost.retail); return str; } /** * CostData Inner Class */ private class CostData { public double wholesale; // Wholesale cost public double retail; // Retail cost /** * CostData class constructor */ public CostData(double w, double r) { wholesale = w; retail = r; } } }
Thls program must be written using thls UML CashRegister TAX RATE : double - 0.06 retail: double quantity int + CashRegister(item Retailltem, q : int) +getSubtotal double +getTax) : double + getTotal0 double CashRegister.Java CashReglsterDemo.Java

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

Why are ratios and trends used in financial analysis?

Answered: 1 week ago

Question

What are the cost limitations?

Answered: 1 week ago

Question

What results did this produce?

Answered: 1 week ago

Question

What are the criteria for a good solution?

Answered: 1 week ago