Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import json class InventoryItem: def __init__( self, itemName ): self.name = itemName self.totalStocked = 0 self.totalInStock = 0 self.totalSlots = 0 def addToStocked( self, stockAmt

image text in transcribed

import json

class InventoryItem: def __init__( self, itemName ): self.name = itemName self.totalStocked = 0 self.totalInStock = 0 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 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 )

def main(): inventoryFileNames = ["REID_1F_20171004.json", "REID_2F_20171004.json", "REID_3F_20171004.json"] itemNameToInventoryItem = {} for inventoryFileName in inventoryFileNames: inventoryFile = open( inventoryFileName, 'r' ) inventoryData = json.loads( inventoryFile.read() ) contents = inventoryData['contents'] for row in contents: for slot in row['slots']: itemName = slot['item_name'] inventoryItem = itemNameToInventoryItem.get( itemName, InventoryItem( itemName ) ) inventoryItem.addToStocked( slot['last_stock'] ) inventoryItem.addToInStock( slot['current_stock'] ) inventoryItem.incrementSlots(); itemNameToInventoryItem[itemName] = inventoryItem cokeItem = itemNameToInventoryItem['Coke']

sortChoice = '' inventoryItemsList = list( itemNameToInventoryItem.values() ) while sortChoice != 'q': sortChoice = input('Sort by (n)ame, (p)ct sold, (s)tocking need, or (q) to quit: ') if sortChoice == 'n': inventoryItemsList.sort( key=InventoryItem.getName ) elif sortChoice == 'p': inventoryItemsList.sort( key=InventoryItem.getSoldPct ) inventoryItemsList.reverse() elif sortChoice == 's': inventoryItemsList.sort( key=InventoryItem.getStockNeed ) inventoryItemsList.reverse() print( 'Item Name Sold % Sold In Stock Stock needs') for item in inventoryItemsList: print( '{:20} {:8} {:8.2f}% {:8} {:8}'.format( item.getName(), item.getNumberSold(), item.getSoldPct() * 100, item.getNumberInStock(), item.getStockNeed())) print() main()

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 modifciations 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)nventory report? m Label REID_1F REID2F REID 3F Pct Sold Sales Total 52.40%$ 230.25 42.02% $ 138.25 52.07% $ 214.75 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 modifciations 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)nventory report? m Label REID_1F REID2F REID 3F Pct Sold Sales Total 52.40%$ 230.25 42.02% $ 138.25 52.07% $ 214.75

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions