QuestionQuestion

Transcribed TextTranscribed Text

2. [vending status checker.py Modify the vending status checker to now also report on the status of the machines overall. Our current vending status checker produces an inventory report. For each machine's inventory file it is counting how many of each beverage were stocked last time, how many of that beverage are currently in stock, and how many slots the beverage occupies (i.e., each slot holds 8 beverages). Your goal is to modify the program such that it can also produce a machines' sales report, something like this: Label Pct Sold Sales Total REID_1F 52.40% $ 230.25 REID_2F 42.02% $ 138.25 REID_3F 52.07% $ 214.75 This report contains three fields: the label of the vending machine, what percentages of the beverages it was last stocked with are sold, and how many total dollars of sales has this generated. You will need to create a new dictionary where the keys are the vending machine labels, and the values are a new type of object called a MachineStatus For each instance, the `MachineStatus) class should store: the label of a vending machine the total amount of beverages the vending machine was previously stocked with the total amount of beverages currently in stock in the vending machine the total income of the machine from the last time it was stocked until now (note: beverages have different prices, so you cannot simply multiply the change in stock times $1.50 to get the total income) Three major modificiations to vending_status_checker.py are necessary: adding the MachineStatus class adding to the loop for counting beverages additional code for counting and updating a vending machine's MachineStatus object values enabling a user to choose the machines' sales report, not just the inventory report, and then display the report as shown in the following example Would you like the (m)achine report or the (i)ventory report? n Label Pct Sold Sales Total REID_1F 52.40% $ 230.25 REID_2F 42.02% $ 138.25 REID_3F 52.07% $ 214.75 HINT: Start by making sure you understand how the counting is done for inventory, most importantly how the dictionary is used to go from the name a beverage to its Inventoryltem) object. Then create a new dictionary with vending machine labels as keys that maps to the vending machine's MachineStatus object. There should be only one MachineStatus object for each vending machine.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import json

class MachineStatus:

    def __init__(self, label):

       self.label = label
       # The total number of beverages that were stocked last time we stocked the machine
       self.totalStocked = 0
       # The total number of beverages still left in the vending machine
       self.inStock = 0
       self.income = 0

    def addBeverage(self, lastStock, inStock, price):

       self.income += (lastStock - inStock) * price
       self.totalStocked += lastStock
       self.inStock += inStock

    def getLabel(self):

       return self.label

    def sales(self):

       return self.income

    def pctSold(self):

       return 100 * (self.totalStocked - self.inStock) / self.totalStocked
   
    def __repr__( self ):
       return '{} In Stock: {}, Stocked: {}, Sold: {}%'.format( self.label, self.inStock, self.totalStocked, round(self.pctSold(), 2) )

class InventoryItem:
    def __init__( self, itemName ):
       # The name of the beverage, we work under the assumption there will only be one InventoryItem
       # for each named beverage
       self.name = itemName
       # The total number of this beverage item that were stocked last time we stocked the machines
       self.totalStocked = 0
       # The total number of this beverage item still left in the vending machines
       self.totalInStock = 0
       # The total number of slots that have this beverage
       self.totalSlots = 0
      
    def addToStocked( self, stockAmt ):
       self.totalStocked = self.totalStocked + stockAmt
      
    def addToInStock( self, inStockAmt ):
       self.totalInStock = self.totalInStock + inStockAmt
      
    def incrementSlots( self ):
       self.totalSlots = self.totalSlots + 1

    def getNumberSold( self ):
       return self.totalStocked - self.totalInStock
   
    def getSoldPct( self ):
       return self.getNumberSold() / self.totalStocked
   
    # We have an assumption here that the total number beverages that can be stocked
    # in a slot is 8 beverages.
    def getStockNeed( self ):
       return 8 * self.totalSlots - self.totalInStock
   
    def getName( self ):
       return self.name

    def getNumberInStock( self ):
       return self.totalInStock

    def __repr__( self ):
       return '{} In Stock: {}, Stocked: {}, Slots: {}'.format( self.name, self.totalInStock, self.totalStocked, self.totalSlots )...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$20.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats