y Comp 115: PrgAsst 06

Comp 115 Programming Assignment 06: Store Inventory

Due 11:59pm Thursday, May 7 2020

This assignment is optional, there is no penalty for not submitting the assignment. However, students who submit a working program on time (no extension allowed on this assignment) will receive a few bonus points (I have not yet decided exactly how many, but probably around 3 points on the final grade).

You are required to work on this lab in teams of two. You must complete this lab with your teammate only, although you may discuss lab concepts with other students. Please keep the Academic Integrity Policy in mind---do not show your code to anyone outside of the professors and tutors, and do not look at anyone else's code for this lab. If you need help, please post a question on Piazza, or contact the professor.

In this project, you will practice computing with classes and objects, as well as everything else we have seen in this course. Save your code in a file whose name consists of the first letter of your first name followed by your last name and Prg6. For example, if I submitted an assignment, I would name the file mgagnePrg6.py. .

The Problem

In Programming Assignment 3, you did such a good job of implementing the program of the candy machine that all the stores of the region now want you to write a program to manage their sales!

However, it is late in the semester, but you should still have time to write a quick program to do at least part of the job.

Input

First, the program should ask the user to enter the name of an input file that contains the inventory of the store.

The program should then read the file to get the information on all the items in the inventory, their name, price and code. Each line of the file will contain three "words", the first word is the name of the product, the second "word" is a floating point number describing the price and the third "word" is an integer describing the quantity of the product in stock. The file inventory.txt is an example of an inventory file, but you should build other examples on your own to test your program.

Finally, the program should ask the user to enter the code of the products they want to buy. The program should ask the user for more codes until the user leaves a blank line.

Output

After each product code entered, if the code corresponds to a product available in the inventory, the program should print the name of the product and its price, as well as the sum of the price of all the products purchased so far (including the product just entered). If the product is not in the inventory (either because the code does not exist, or the remaining quantity of the product is zero), the program should print that the product is not available and just reprint the sum of the prices of all the products purchased so far.

Once the user entered a blank line, the program should print the total price of the items purchased one last time.

A typical run of the program should look something like this:

  Please enter the name of the file: inventory.txt
  Please enter the code of the item you would like to purshase: S398F2C1
  You purchased a hammer, its price is $11.99
  Your total is now $11.99
  Please enter the code of the item you would like to purshase: A65SJER3
  You purchased a nail, its price is $0.02
  Your total is now $12.01
  Please enter the code of the item you would like to purshase: ZZZZZZZZ
  I am sorry, this item is not in the inventory
  Your total is now $12.01
  Please enter the code of the item you would like to purshase: A65SJER3
  You purchased a nail, its price is $0.02
  Your total is now $12.03
  Please enter the code of the item you would like to purshase:               <blank line>
  Your final total is $12.03
Specifics

Your program should include a class called InventoryItem that contains 4 variables: a name, a code, a price and a quantity. The class should also contain the following methods:

Your program should also include the following functions:

Otherwise, you are allowed to organize your code anyway you want, as long as there is no more than one loop in each function.

Naturally, every time a product is purchased, the quantity of that product should be reduced by one in the InventoryItem object storing the information of that product. So it should not be possible for a user to buy a quantity of a product that is greater than what is in the inventory.

Notes

Like the previous assignment, your submitted assignment should start with a header containing the name of the author(s), filename, description of the program, input and output.

I recommend that you sketch a plan of the tests you intend to use before you start writing code, otherwise this could get messy. Five minutes of planning could save you an hour of debugging! You can also test your program by printing the result at the end of each step to see if each step is doing what you were expecting them to do (just remember to remove those prints before submitting the program).

Test your program carefully. You should try to have a test case that explores every possible "path" in your code, and think of special inputs that might cause problems.

The program is getting a little large now, so picking meaningful names for your variables will make the program that much easier to read and make all the information easier to access.

You can write more comments in your code to explain what is going on if you feel it is appropriate. It's never harmful to explain to the next person reading your code (or grading your code)