Q Write a CashRegister class that can be used with the RetailItem class that you wrote in Chapter 6’s Programming Challenge 4. 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 passes as an arugument 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 sale’s subtotal, amount of sales tax, and total

The CashRegister class is designed to simulate the sale of a retail item. It is meant to be used in conjunction with the RetailItem class from Chapter 6’s Programming Challenge 4. The CashRegister class has a constructor that accepts a RetailItem object as an argument, along with an integer representing the quantity of items being purchased.

The CashRegister class has three methods: getSubtotal, getTax, and getTotal.

The getSubtotal method calculates and returns the subtotal of the sale, which is the quantity multiplied by the price of the item. This method retrieves the price of the item from the RetailItem object passed to the constructor.

The getTax method calculates and returns the amount of sales tax on the purchase. The sales tax rate is fixed at 6% of the retail sale.

The getTotal method calculates and returns the total amount of the sale, which is the sum of the subtotal and the sales tax.

To demonstrate the CashRegister class, we can create an instance of the class and ask the user for the quantity of items being purchased. We can then display the sale’s subtotal, the amount of sales tax, and the total.

Here is an example implementation:

“`python
class CashRegister:
def __init__(self, item, quantity):
self.item = item
self.quantity = quantity

def getSubtotal(self):
return self.quantity * self.item.getPrice()

def getTax(self):
return self.getSubtotal() * 0.06

def getTotal(self):
return self.getSubtotal() + self.getTax()

# Demonstration of the CashRegister class
def main():
# Create a RetailItem object
item = RetailItem(“Shirt”, 100, 19.99)

# Ask the user for the quantity of items being purchased
quantity = int(input(“Enter the quantity of items being purchased: “))

# Create a CashRegister object
register = CashRegister(item, quantity)

# Display the sale’s subtotal, amount of sales tax, and total
print(“Subtotal:”, register.getSubtotal())
print(“Sales Tax:”, register.getTax())
print(“Total:”, register.getTotal())

# Run the main function
if __name__ == “__main__”:
main()
“`

In this example, we assume that the RetailItem class has a getPrice method to retrieve the price of the item. The user is prompted to enter the quantity of items being purchased. Then, a CashRegister object is created using the RetailItem object and the quantity. Finally, the sale’s subtotal, amount of sales tax, and total are displayed.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer