ECS32A University of California CH9 Program The Evil Register Analysis Paper

Background

Think about a receipt that you have gotten from a recent shopping trip. (I just know you all read your receipts and file them if they contain any warranty-bearing goods!) You’ll notice that the order of the items on the receipt is usually just the order the items were scanned in. Target sorts the items by department. But, if you think about it, the line items on the receipt should be sorted in descending order of price. That way, if the cashier or self-checkout system made a mistake, you would spot the biggest mistake first. On the other hand, if a store wanted to be evil they would put the least expensive items first, to remind you of all the good deals you got while forgetting about the costlier scanning mistakes at the register.

The ItemToPurchase class

If you haven’t done so already, make sure to complete zyLab 9.11 before this one. Otherwise, you will have to implement the ItemToPurchase class from scratch and this zyLab won’t make much sense.

Customizing the ItemToPurchase class

Calculating the “total price” of an item is tedious, so implement a get_item_cost method that just returns the quantity times the price for an item. By the way, the technical term for this kind of instance method is an accessor method, but you’ll hear developers calling them getters because they always start with “get” and they get some value from instance attributes.

In order to make the items sortable by their total total price, we need to customize our class. Search the lectures slides for “magic” to see how to do this. See Section 9.8 for an additional reference.

The Receipt class

This will be the class that defines our Receipt type. Obviously, a receipt will consist of the Items on the receipt. This is called the composition design pattern and it is very powerful.

Instance Attributes:

  1. customer_name : It is very important to always know everything you can about your customers for “analytics”, so you will keep track of a string customer name in objects of type Receipt.
  2. date : The legal team has required that you keep track of the dates that purchases happen for “legal reasons”, so you will also keep track of the string date in objects of type Receipt.
  3. cart_items : This will be a list of the items in the cart and hence end up on the receipt. The items in this list will end up being of type ItemToPurchase.

Instance Methods

  1. Create a default constructor that can take a customer name as an argument, but if it gets no customer name, it will just put “Real Human” for the customer_name attribute. That is, it will have a default value of “Real Human.” It should also accept a date argument, but will just use the value “Today” for the date instance attribute if no date is given. The parameters should be named the same as the instance attributes to keep things simple.
  2. add_item : Self-descriptive. Takes a parameter which we hope beyond hope is of type ItemToPurchase and adds it to the cart_items. Returns None. Again, the single item parameter is expected to be of type ItemToPurchase.
  3. print_receipt : Takes a parameter isevil, with default value True. Returns a total cost of all the items on the receipt (remember to factor in the quantity). Prints the receipt based on the following specification:
    For example, if isevil is True, and customer_name and date are the default values:

Otherwise, it should print:

Then, also in the print_receipt method, the receipt should be printed in sorted order like we discussed earlier, but whether or not it starts with the highest cost (think reverse), depends on the value of isevil. If it is evil, then the lowest cost items should print first, but if it is good, then it will print the highest cost items first. (Cost meaning the itemprice*itemquantity, or the result of the get_item_cost()method from above).

Remember to return the total cost from the print_receipt() method regardless!

Your main() function:

The main flow of control of your program should go in a main() function or the program will fail all the unit tests.

Get the name of the customer with the prompt: Enter Customer Name:
Get the date with the prompt: Enter Today's Date Then, ask the question: Are you evil? Your program should consider the following as True:
Yeah
yup
Let's face it: yes
Hint: What do these strings all have in common?
Your program should consider all the following as False:
No
nah
perhaps but I'm leaning no
(Just be glad you don’t have to handle “yeah no.”)

Okay enough horsing around. (GET IT? Aggies?! Horsing!)
Next, in the main() function, you will have to create a Receipt object and start adding things into it using an input-while loop.
The loop will prompt the user for the item name exactly as in the previous zyLab (9.11). But unlike the previous zyLab, the loop will terminate only if an empty string is entered for the item name.

Then, the price and the quantity will be prompted for exactly as in the previous zyLab. Create the ItemToPurchase objects in the same manner as the previous zyLab, but don’t forget to add them to the receipt using your add_item instance method.

Then, the items on the receipt should be printed with the same formatting as in the previous zyLab, of course with either “good” or “evil” ordering.

However, on the last line, the total should be printed as follows:

Where 10 is replaced by the actual total.

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.