Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. Write a CashRegister class that can be used with the RetailItem class that you wrote in Lab 2 (Question #3). The CashRegister class should

4. Write a CashRegister class that can be used with the RetailItem class that you wrote in Lab 2 (Question #3). 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 print the sales receipt.

Draw UML diagram to show the relationship between all classes. (In java uml diagram, not full program) thank you

This is my previous program:

public class RetailItem { private String description; private int units; private double price; public RetailItem() {

} public RetailItem(String des,int u, double p) { description = des; units = u; price = p; } public void setDescription(String des) { description = des; } public void setPrice(double p) { price = p; } public void setUnits(int u ) { units = u; } public int getUnits() { return units; } public String getDescription() { return description; } public double getPrice() { return price; } }

public class RetailTest { public static void main(String[] args) { //RetailItem with 3 objects RetailItem r1 = new RetailItem("JEANS",50,99.99); RetailItem r2 = new RetailItem("SHORT PANTS",100,79.99); RetailItem r3 = new RetailItem("SKIRTS",60,59.99); //outputting data System.out.println("_______________________________________________________"); System.out.println("\tDescription\tUnitsOnHand\tPrice"); System.out.println("_______________________________________________________"); System.out.println("Item 1\t" + r1.getDescription() + "\t\t" + r1.getUnits() + "\t\t" + r1.getPrice()); System.out.println("Item 2\t" + r2.getDescription() + "\t" + r2.getUnits() + "\t\t" + r2.getPrice()); System.out.println("Item 3\t" + r3.getDescription() + "\t\t" + r3.getUnits() + "\t\t" + r3.getPrice()); System.exit(0); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions