Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use Java: Cash Register simulation In this programming challenge, you wil

ID: 3885552 • Letter: P

Question

Please use Java:

Cash Register simulation In this programming challenge, you will simulate a cash register. The client program will work like this: You will use an array or ArrayList to simulate a shopping cart. You will add Retail!tem objects to your shopping cart. The CashRegister class will process the Retail Items in your cart Create a sales receipt that is an itemization of all the items in your shopping cart and a total cost for all items properly formatted. Use the following UML diagrams to create the class objects, Retailltem and CashRegister. The classes should have appropriate constructor(s), accessor, and mutator methods A Retailltem holds the data about an item in a retail store. The class should have the following fields: description: The description field references a String object that holds a brief description of the item price: The price field is a double that holds the item's retail price numOfpurchase . The numOfpurchase field is an int that holds the quantity of items in cart RetailItem - description : String - price: double - numofpurchase: int +RetailItem (d String, p : double, n : int) +setDescription (d string): void +setPrice (p: double): void +setNumOfPurchase (n : int) : void +get Description () : String +get Price() double +getNumOfPurchase() : int A CashRegister object will process each Retailltem to determine cost of item with tax. It will simulate the sale of a retail item. It should have a constructor that accepts a Retailltem object as an argument. In addition, the class should have the following instance variables and methods: retailPrice : The retai!Price field will store the price of the RetailItem being passed to constructor. quantity. The quantity field will store the quantity of the current Retail!tem in your cart. The SubTotal method should return the subtotal of the sale, which is the quantity multiplied by the retail price.

Explanation / Answer

CashRegisterTest.java

import java.text.DecimalFormat;

public class CashRegisterTest {

public static void main(String[] args) {

RetailItem items[] = new RetailItem[10];

items[0] = new RetailItem("gallon of Milk", 3.29, 1);

items[1] = new RetailItem("dozens of eggs", 3.58, 2);

items[2] = new RetailItem("box of cereal", 10.47, 3);

items[3] = new RetailItem("Del Turkey", 13.98, 4);

items[4] = new RetailItem("Rolls", 7.92, 5);

items[5] = new RetailItem("half gallon Ice Cream", 8.98, 2);

items[6] = new RetailItem("box of cookies", 10.47, 5);

items[7] = new RetailItem("zip storage bags", 14.45, 6);

items[8] = new RetailItem("apples", 2.97, 1);

items[9] = new RetailItem("toilet paper rolls", 8.90, 2);

System.out.println(" Sales Receipt");

DecimalFormat df = new DecimalFormat("0.00");

System.out.println("------------------------------------------");

CashRegister c = null;

for(int i=0;i<items.length;i++) {

c = new CashRegister(items[i]);

System.out.println((i+1)+" "+items[i].getDescription()+" "+items[i].getPrice());

}

System.out.println("==========================================");

System.out.println(" Tax = "+df.format(c.getTax()));

System.out.println(" Total Due = "+df.format(c.getTotal()));

}

}

CashRegister.java

public class CashRegister {

private double TAX_RATE = 0.06;

private static double retailPrice;

private static int quantity;

public CashRegister(RetailItem item) {

retailPrice+=item.getPrice();

quantity+=item.getUnitsOnHand();

}

public double getSubtotal() {

return retailPrice;

}

public double getTax() {

return retailPrice * TAX_RATE;

}

public double getTotal() {

return getSubtotal()+getTax();

}

}

RetailItem.java

public class RetailItem {

private String description;

private int unitsOnPurchase;

private double price;

public RetailItem(String description, double price, int unitsOnPurchase ){

this.description = description;

this.unitsOnPurchase = unitsOnPurchase;

this.price = price;

}

public String getDescription() {

return description;

}

public void setDescription(String description) {

this.description = description;

}

public int getUnitsOnHand() {

return unitsOnPurchase;

}

public void setUnitsOnHand(int unitsOnHand) {

this.unitsOnPurchase = unitsOnHand;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

}

Output:

Sales Receipt

------------------------------------------

1 gallon of Milk 3.29

2 dozens of eggs 3.58

3 box of cereal 10.47

4 Del Turkey 13.98

5 Rolls 7.92

6 half gallon Ice Cream 8.98

7 box of cookies 10.47

8 zip storage bags 14.45

9 apples 2.97

10 toilet paper rolls 8.9

==========================================

Tax = 5.10

Total Due = 90.11