Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Retail stores need to maintain an accurate record of their inventory-the items available for purchase and the quantity of each item in stock. For
Retail stores need to maintain an accurate record of their "inventory"-the items available for purchase and the quantity of each item in stock. For this project, you will write a program to help a small store manage their inventory. The program will read in the inventory from a file, and allow the user to list items, search for items, and make purchases, which will decrease the item quantities. When the user decides to quit, the updated inventory will be output to a file. File Format A common format for data files is one in which the fields on each line are separated by commas. This type of file is known as a Comma-separated Value (CSV) file and is the type of file used in this project. Excel spreadsheet files, with which you may be familiar, can be exported as CSV files. The user will provide the initial inventory as a text file in CSV format. When the program ends, the updated inventory will be output as a text file using the same CSV format. Each line of the CSV inventory files used in the project will contain three fields separated by commas-the item identifier (id), the item name, and the item quantity. Your program will need to determine if the input file is valid, i.e., it contains three values on each line, that the quantity for each item is an integer that is greater than or equal to 0, and that the item ids are unique, i.e, no two items have the same id. Below is an example of a file that contains the items in an office supply store inventory: PE0195, pencil,34 MP8917, mechanical pencil,8 DP8768, drawing pencils, 5 NP1800, notepad, 4 P19076,black pen, 35 P90557,blue pen, 16 PM1889, black permanent marker, 12 DE6785,black dry erase marker, 8 DE8079, red dry erase marker, 13 BS3045, box of staples, 15 PC8866, small paper clips, 23 PC9876, large paper clips, 12 T91180, tape, 20 MT4987, masking tape, 45 JAVA 1 // Returns a String with each item whose name is/contains itemName, disregarding case, 2 // with the item id, name, and quantity formatted as shown above with a newline character after the String for each item. 3 // 4 // 5 // Use the provided toString() method below to ensure that the formatting of each line is correct. 6 // 7 // 8 // If none of the items have a name that is or contains itemName, 9 // the empty string ("") is returned. 10 // 11 // Throws an IllegalArgumentException with the message 12 // 13 // "Null array" if itemIds, itemNames, and/or itemQuantities are/is null 14 // Throws an IllegalArgumentException with the message 15 // "Invalid array Length" if the lengths of itemIds, itemNames, and itemQuantities arrays 16 // are not the same 17 // 18 // NOTE: You must check for invalid parameters (arguments) in the order given above. 19 public static String searchByName(String[] itemIds, String[] itemNames, 20 21 22 } 22 int[] itemQuantities, String itemName) { PE0195, pencil,34 MP8917, mechanical pencil, 8 DP8768, drawing pencils, 5 NP1800, notepad, 4 P19076,black pen, 35 P90557,blue pen, 16 PM1889, black permanent marker, 12 DE6785,black dry erase marker, 8 DE8079, red dry erase marker, 13 BS3045,box of staples, 15 PC8866, small paper clips, 23 PC9876, large paper clips, 12 T91180, tape, 20 MT4987, masking tape, 45
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started