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

In this programming challenge, you will simulate a cash register. The client pro

ID: 3885532 • Letter: I

Question

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 stimulate a shopping cart. You will add RetailItem objects to your shopping cart. The CashRegister class will process the RetailItems 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, RetailItem and CashRegister. The classes should have appropriate constructor(s), accessor, and mutator methods. A RetailItem holds the data about an Item in a retail store. The class should have the following fields: description: The description field references a String objects 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 A CashRegister object will process each RetialItem to determine cost of item with tax. It will stimulate the sale of a retail Item. It should have a constructor that accepts a RetailItem object as an argument. In addition, the class should have the following instance variables and methods: retailPrice: The retailPrice field will store the price of the RetialItem being passed to constructor. quantity: The quantity field will store the quantity of the current RetailItem in your cart. The subTotal method should return the subtotal of the sale, which is the quantity multiplied by the retail price. 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. The client program should create an array or ArrayList of 10 RetailItem objects. The client should process your cart and determine an Itemized sales receipt that shows total for each Item and total for your shopping cart, including a separate line for total tax paid. Make sure to use class methods for tasks in your client program. You can use a file, coded or interactive input for all retail items. Make sure to include documentation of classes and client and output that has tested your program completely before submitting. Sample Output:

Explanation / Answer

//RetailItem.java

package shoppingcart;

public class RetailItem {

// creating class member variables description,price,noOfpurchase

   private String description;
   private double price;
   private int numOfpurchase;

// creating setters and getters of class members
   public String getDescription() {
       return description;
   }
   public void setDescription(String description) {
       this.description = description;
   }
   public double getPrice() {
       return price;
   }
   public void setPrice(double price) {
       this.price = price;
   }
   public int getNumOfpurchase() {
       return numOfpurchase;
   }
   public void setNumOfpurchase(int numOfpurchase) {
       this.numOfpurchase = numOfpurchase;
   }

// creating RetailItem parameterised constructor

//we accepting parameters as description,price,numofpurchase
   public RetailItem(String description, double price, int numOfpurchase) {
       super();
       this.description = description;
       this.price = price;
       this.numOfpurchase = numOfpurchase;
   }

// optional toString() if u want to delete , u can.
   @Override
   public String toString() {
       return "RetailItem [description=" + description + ", price=" + price + ", numOfpurchase=" + numOfpurchase + "]";
   }
  
  
  
}


// CahRegister.java

package shoppingcart;

public class CashRegister {

   private final double TAX_RATE=0.06; // taking tax_rate as constant value

// 2 class members retailPrice and quantity


   private double retailPrice;
   private int quantity;

// CashRegister Constructor, which is accepting RetailItem object and initialize quantity and reatilPrice

  
   public CashRegister(RetailItem item){
   this.quantity=item.getNumOfpurchase();
   this.retailPrice=item.getPrice();
   }
  

// It returns the price * quantity of retail item
   public double getSubTotal(){
       return quantity*retailPrice;
   }
  

// it returns the price*tax_rate(0.06) of retail item
   public double getTax(){
       return retailPrice*TAX_RATE;
              
   }
  

// it returns the subtotal+tax
   public double getTotal(){
      
       return getSubTotal()+getTax();
   }
  
  
  
  
}


// Client.java

package shoppingcart;

import java.util.ArrayList;

public class Client {

   public static void main(String[] args) {
        // creating arrayList and pass RetailItem objects
       ArrayList<RetailItem> reatilItems=new ArrayList<RetailItem>();
       CashRegister cash=null;
       reatilItems.add(new RetailItem("gallon of milk",5,1));
       reatilItems.add(new RetailItem("dozen of eggs",60,2));
       reatilItems.add(new RetailItem("box of ceral",20,3));
       reatilItems.add(new RetailItem("half gallon Ice Cream",15,2));
       reatilItems.add(new RetailItem("apples",25,1));
      
        double tax_calculate=0l; // to calculate tax of all items
       double total_bill=0l; // to calculate the sum of total items money
       System.out.println("Sales Reciept");
       System.out.println("-----------------------------------------------------");
       for(RetailItem item: reatilItems){
           cash=new CashRegister(item);
           System.out.println(item.getNumOfpurchase()+"     "+item.getDescription()+"                "+cash.getSubTotal());
           tax_calculate+=cash.getTax();
           total_bill+=cash.getTotal();
       }
       System.out.println("-----------------------------------------------------");
  
       System.out.println("                                  Tax      "+tax_calculate);
       System.out.println("                             Total Due     "+String.format( "%.2f",total_bill ));
      
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote