Assignment 3: Inventory Program

Unlike previous assignments, you will be writing just one program for this assignment. It will focus on functions, files, loops, and modules; it will also give you practice writing a larger program.

Background

You have been hired by a company to write a system for tracking their inventory. Below, the company describes the needs of their software. The products they sell, the quantity of each, and their prices are stored in a file. The layout of the file is also described below.

Specification

The program should first ask the user for the input filename (which contains the inventory information) and load that file. A sample inventory file can be found here: inventory.dat. The first row holds the current company balance. Each line after that has information about the products. The first field contains the name of the product. The second field contains the price we sell the product at, and the third field is our current quantity. The fields are delimited by whitespace.

After loading the file, present the user with the main menu containing each product (including the quantity and price) and an option to exit the program. Also display the current balance. An example menu for the inventory file above is:

Current balance: $3000.00
 1. Lamps                (400 at $15.30)
 2. Chairs               (250 at $19.95)
 3. Desks                (300 at $95.00)
 0. Exit

Please enter choice:

If the user selects one of the products, present another menu to them (the product menu). Assuming the user chooses Lamps, the menu should look like:

Current balance: $3000.00
Current quantity: 400
Current price: $15.30
 1. Sell Lamps
 2. Buy Lamps
 3. Change price
 0. Return to main menu
Please enter choice:

Once the action has been completed, return to the menu. Below is an example of each action.

Current balance: $3000.00
Current quantity: 400
Current price: $15.30
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 1

Amount to sell (current quantity: 400): 300
-----------------------------------
Current balance: $7590.00
Current quantity: 100
Current price: $15.30
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 2

Amount to buy: 50
Price per item: 10
-----------------------------------
Current balance: $7090.00
Current quantity: 150
Current price: $15.30
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 3

New price: 20
-----------------------------------
Current balance: $7090.00
Current quantity: 150
Current price: $20.00
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 1

Amount to sell (current quantity: 150): 200
Warning: Selling more than is in stock!
Do you wish to proceed (yes or no)? yes
-----------------------------------
Current balance: $11090.00
Current quantity: -50
Current price: $20.00
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice:

When the user exits the program, save the inventory to the same file that had been used to load the inventory information (overwriting the information stored in it). The program should not ask for the filename again.

Below is a complete run of the program using the input file referenced above (inventory.dat)

Please enter input filename: inventory.dat
Current balance: $3000.00
 1. Lamps                (400 at $15.30)
 2. Chairs               (250 at $19.95)
 3. Desks                (300 at $95.00)
 0. Exit

Please enter choice: 1
-----------------------------------
Current balance: $3000.00
Current quantity: 400
Current price: $15.30
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 1

Amount to sell (current quantity: 400): 300
-----------------------------------
Current balance: $7590.00
Current quantity: 100
Current price: $15.30
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 2

Amount to buy: 50
Price per item: 10
-----------------------------------
Current balance: $7090.00
Current quantity: 150
Current price: $15.30
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 3

New price: 20
-----------------------------------
Current balance: $7090.00
Current quantity: 150
Current price: $20.00
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 1

Amount to sell (current quantity: 150): 200
Warning: Selling more than is in stock!
Do you wish to proceed (yes or no)? yes
-----------------------------------
Current balance: $11090.00
Current quantity: -50
Current price: $20.00
1. Sell Lamps
2. Buy Lamps
3. Change price
0. Return to main menu
Please enter choice: 0

Current balance: $11090.00
 1. Lamps                (-50 at $20.00)
 2. Chairs               (250 at $19.95)
 3. Desks                (300 at $95.00)
 0. Exit

Please enter choice: 0

Once the program ends, the file inventory.dat now should contain:

11090.0
Lamps 20.0 -50
Chairs 19.95 250
Desks 95.0 300

Implementation Details

Be sure to validate input. The user should not be allowed to enter negative prices or quantities. When selecting an option from one of the menus, make sure they only enter a valid meny option. If an invalid option was selected, display an error message, display the menu again, and wait for input.

Your program should not crash. Use exception handling to handle any cases where the program could crash.

Write and use at least five functions for this program. Some of the functions you will probably use have already been written by you in labs. In the assignment information sheet, explain why you chose to write the functions you did.

You are not required to create your own classes in implementing this program. However, you may find that creating one or more classes will make the program easier.

Be sure to properly document your functions.

Extra Credit

Add New Products

Allow the user to add new products. The main menu will still list the products, starting the count at 1. The "Exit" option still has option 0. However, there is a new menu option: "Add new item". This new menu option will always have the next number as its numeric option. So, in the case of three products (numbered 1 to 3), the "Add new item" option will be numbered 4. After adding a product, the four products will be numbered 1 to 4 and the "Add new item" option will be moved to 5.

If the user asks to add a new product to the inventory, ask for the product's name, the initial quantity in stock, and the price per item. Check to make sure a product with that name does not already exist (ignore capitalization when performing this check). If a product does exist, ask for a new name. Also make sure that the quantity and price are valid. If either is not, repeatedly ask until the value is valid. Once the new product has been added, return to the main menu.

Adding a new product requires buying that product. Use the quantity and price entered to determine how much the company paid for the product and deduct that from the company's balance.

Here is an example of adding a new item:

Current balance: $11090.00
 1. Lamps                (-50 at 20.00)
 2. Chairs               (250 at 19.95)
 3. Desks                (300 at 95.00)
 4. Add new item
 0. Exit

Please enter choice: 4
Enter name of new item: Chairs
Error: product already exists!
Please enter a new name: chairs
Error: product already exists!
Please enter a new name: Computers
Enter starting quantity: 20
Enter price per item: 400
Current balance: $3090.00
 1. Lamps                (-50 at 20.00)
 2. Chairs               (250 at 19.95)
 3. Desks                (300 at 95.00)
 4. Computers            (20 at 400.00)
 5. Add new item
 0. Exit

Please enter choice:

Multi-Word Products

Allow the products to have multi-word names. The way the input file is designed, multi-word names, like "Desk Chair", would be hard/impossible to use. Design your program to handle multi-word names. You may redefine the layout of the input file (be sure to mention any changes in your assignment information sheet).

Final Notes:

Submission and Grading:

Complete the Assignment Information Sheet.

Submit your final program and assignment information sheet (zipped into one file) to CourseWeb in the Assignment 3 assignment.

The grading rubric can be found here: Rubric (doc).

The assignment is due Friday, July 31 by 11:59 pm. As with all programming assignments, you have unlimited uploads (before the deadline), so you may upload the assignment before the deadline. If you later decide to upload another, you may do so without penalty (as long as it's before the assignment deadline). The last submission uploaded before the deadline will be the one graded. If you would like ungraded feedback on a programming assignment, you may send an email to your TA or the instructor and ask for feedback; please send your code as well.

For more advice on submitting your assignment, see the Programming Assignments section of the Tips for Success page.