Question: Objective 1 : Reading Items into a Data StructureThe first objective is to read an input file items.txt , which contains data about what items

Objective 1: Reading Items into a Data StructureThe first objective is to read an input file items.txt, which contains data about what items are available for purchase. Figure 2 shows an example of what this file may contain. You can create an instance of such a file for testing purposes. The actual formatting of the files uses a list of comma-separated values so you can easily read them line-by-line using Javas Scanner class. Once you have read the file, you should store the items in objects of a suitable custom class and add them to an appropriate data structure.The following requirements must be completed to get full marks for this objective: You should create a function called readItems(filename) that takes as input theitems.txt and adds items to a data structure. It does not need to return anything. Measure the running time for running this function. State the asymptotic worst-case time and space complexity of your function using Big-O notation. Objective 2: Item InventoryThe second objective is to allow the user to manage and query the inventory. The following requirements must be completed to get full marks for this objective: You should create a function called addItem(id, name, stock, price) that takes as input the attributes of a new item then adds a new item to your data structure. It returns true if the addition was successful and false otherwise.You should create a function called updateItemStock(id, newStock) that takes as input the item ID and the new stock then updates the items stock accordingly. It returns true if the update was successful and false otherwise.You should create a function called getStock(id) that takes as input the item ID and returns the stock available for that item.All of the above functions must run in worst-case time O(lg n) or less, where n is the number of items.Measure the running time for all functions.Compare your running time of getStock to another function getStockFromArray where items are stored in a simple array instead of the data structure that you initially chose in Objective 1.Objective 3: Purchasing OperationsThe third objective is to allow the user to initiate and maintain purchases of items. The following requirements must be completed to get full marks for this objective:You should create a method called addNewPurchase(arrayOfIds) that accepts an array of items IDs and deducts one stock from each item specified in this area. For example if arrayOfIds =[2,9,4] then it will remove one unit from the stock of item 2, item 9, and item 4. The method will return the total price for this purchase or an error if there is not enough stock for the selected items.You should create a method called undoLastPurchase(k) that undoes the last k pur- chases. The stocks if those items need to be reverted back to their original values.Objective 4: Most Profitable ItemThe fourth objective should allow the user to find the purchase that yielded the highest value (defined as the total price of all items in that purchase). For example, Figure 3 shows some purchases that can be made by the user using the items from Figure 2. The highest priced purchase would be Purchase 3 in this case. You should create a function called highestPriced() that returns ID of the purchase with the highest total price. The above function must run in worst-case time O(lgn) or better, where n is the number of customers. Measure the running time of your function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!