In Java, please follow the steps below to complete this inventory counter program. In addition, add detailed comments so I can understand your code.
Inventory itemArray: Item [100) InventoryTrackerInterface totalItems: int -0 +getTotalNumberOfItens int +getItem (index:int): Item taddItem (newItem:Item) void +saveInventoryToFile (fileName: String): void +loadinventoryFromFile (fileName: String) vo inv: Inventory Item name: String -quantity: int price: double upc: String Item() +Item (name: String, qty:int, price:double, upc:Strin +getName): String +getOuantity): int +getPrice): double +getUPCO String 1. Milestone 1- Create the InventoryTrackerlnterface Class (5 pts) In this case, just create the shell of the class, and add the main method, but do not fill anything in just yet 2. Milestone 2- Create the Item class and fill in the code (10 pts) The ltem class is pretty easy to create. You will notice that the default construction (no parameters) is private. This is to prevent any other classes from creating an instance without specifying the 4 attributes through the second/public constructor listed. The getName(), getQuantity(), getPrice(), and getUPC() methods simply return the attributes name, quantity, price, and upc respectively Once you have created the Item class, use the main method in the InventoryTrackerlnterface to test out the ltem class. If you are certain the Item class and all its methods are working perfectly, move on to the next milestone Milestone 3- Create the Inventory Class, its attributes, and the getTotalNumberOfltems() method (5 pts) 3. In this milestone you will create the Inventory class and add the attributes. Additionally you will create the getTotalNumberOfltems() method which simply returns the totalltems attribute. Once again you should test out this milestone and by creating an instance in main. If you are sure it is working, move on to the next milestone 4. Milestone 4 Create methods getltem and addltemTolnventory (20 pts) In this milestone you will create the getltem() and addltem() methods. The getltem() method takes a parameter called index that represents an item in the itemArray array. Here's the catch though, while the itemArray has 100 spots (0-99), you will probably have a lot less stored. This is why we have the totalltems attribute. It will keep track of how many items have been added to the array. So as an error check, if index is less than 0, or it is greater than or equal to totalltems return null. If not, go ahead and return itemArray[index]. It is important to note that this will not remove the item from the array. In fact this entire inventory system will not support removing items once they have been added The addltem() take an instance of Item as a parameter called newltem. We need to check to make sure that this is in fact an instance of Item before we add it to the array. We carn do this by checking if the newltem is equal to null. If it is, print out a message saying "Item not added". If newltem is not null you can add the item to the end of the array. It just so happens that totalltems is the index of the next empty position, so we can get away with doing this: itemArray[totalltems] newltem; Since we just added a new item to the array, we are going to have to also update totalltems.(in other words, add 1 to it). At this point you should test out both methods by adding an item, getting that item and then printing out the contents of that item to make sure everything is working correctly. Again you can do this in main. 100% sure it's done? Milestone 5. Milestone 5- Create Methods savelnventoryToFile and loadlnventoryFromFile (20 pts) In this milestone you will create the savelnventoryToFile method and loadlnventoryFromFile method. Use the PrintWriter class to write your inventory to a text file. This means for each process in your array, print the name, quantity, price, and upc (all on different lines I recommend). You can test to see if this is working correctly by looking at the at the text file you tried creating. If you are sure the method is working, try implementing the loadlnventoryFromFile method. This method will instead read in all the inventory information (if the file exists!) into the programs array. Test this method by running the program and immediately running this file. Then try to print out the inventory Milestone 6- Create loop interface with user (10 pts) This is essentially the final milestone. This will go inside main. Each time the loop iterates (loops) you will display a menu to the user (see the example of the program running I provided below) and allow them to enter a choice. Based on the choice you will perform that action (which associates directly to a method for the most part). If the user enters in 5 (exit) the loop will stop looping and the program will end. To figure out which of the 5 options the user chose you should use a SWITCH structure (not a bunch of if statements). Some of the options 1 and 2 will require you to get more information from the user. 5. 6. Here is an example of the programming running once Problems Javadoc Declaration Console
InventoryTrackerinterface [Java cation 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Enter the new items name Banana Enter the new items quantity 52 Enter the new items price 5.55 Enter the new items upc 123456 1 Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Enter the new items name Tomatoe Enter the new items quantity Enter the new items price 67 Enter the new items upc 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Enter the new items name Pepper Enter the new items quantity 500 Enter the new items price 25 Enter the new items upc 000223 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Which item would you like info for? [e-2] Name: Quantity: 555 Price: 0.67 UPC: 1 Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Tomatoe Inventory Saved 1 Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Goodbye! And an example of it running again after saving and exiting in the previous example.... &L Problems @ Javadock > DeclarationConsole Inventory Trackerinterface [Java Application 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit 2 No items in inventory 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit 4 Inventory Loaded 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit 2 Which item would you like info for? [0-2] 1 Name: Quantity: 555 Tomatoe Price: 0.67 UPC: 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit 5 Goodbye! Additional points: Comments: 30 points Inventory itemArray: Item [100) InventoryTrackerInterface totalItems: int -0 +getTotalNumberOfItens int +getItem (index:int): Item taddItem (newItem:Item) void +saveInventoryToFile (fileName: String): void +loadinventoryFromFile (fileName: String) vo inv: Inventory Item name: String -quantity: int price: double upc: String Item() +Item (name: String, qty:int, price:double, upc:Strin +getName): String +getOuantity): int +getPrice): double +getUPCO String 1. Milestone 1- Create the InventoryTrackerlnterface Class (5 pts) In this case, just create the shell of the class, and add the main method, but do not fill anything in just yet 2. Milestone 2- Create the Item class and fill in the code (10 pts) The ltem class is pretty easy to create. You will notice that the default construction (no parameters) is private. This is to prevent any other classes from creating an instance without specifying the 4 attributes through the second/public constructor listed. The getName(), getQuantity(), getPrice(), and getUPC() methods simply return the attributes name, quantity, price, and upc respectively Once you have created the Item class, use the main method in the InventoryTrackerlnterface to test out the ltem class. If you are certain the Item class and all its methods are working perfectly, move on to the next milestone Milestone 3- Create the Inventory Class, its attributes, and the getTotalNumberOfltems() method (5 pts) 3. In this milestone you will create the Inventory class and add the attributes. Additionally you will create the getTotalNumberOfltems() method which simply returns the totalltems attribute. Once again you should test out this milestone and by creating an instance in main. If you are sure it is working, move on to the next milestone 4. Milestone 4 Create methods getltem and addltemTolnventory (20 pts) In this milestone you will create the getltem() and addltem() methods. The getltem() method takes a parameter called index that represents an item in the itemArray array. Here's the catch though, while the itemArray has 100 spots (0-99), you will probably have a lot less stored. This is why we have the totalltems attribute. It will keep track of how many items have been added to the array. So as an error check, if index is less than 0, or it is greater than or equal to totalltems return null. If not, go ahead and return itemArray[index]. It is important to note that this will not remove the item from the array. In fact this entire inventory system will not support removing items once they have been added The addltem() take an instance of Item as a parameter called newltem. We need to check to make sure that this is in fact an instance of Item before we add it to the array. We carn do this by checking if the newltem is equal to null. If it is, print out a message saying "Item not added". If newltem is not null you can add the item to the end of the array. It just so happens that totalltems is the index of the next empty position, so we can get away with doing this: itemArray[totalltems] newltem; Since we just added a new item to the array, we are going to have to also update totalltems.(in other words, add 1 to it). At this point you should test out both methods by adding an item, getting that item and then printing out the contents of that item to make sure everything is working correctly. Again you can do this in main. 100% sure it's done? Milestone 5. Milestone 5- Create Methods savelnventoryToFile and loadlnventoryFromFile (20 pts) In this milestone you will create the savelnventoryToFile method and loadlnventoryFromFile method. Use the PrintWriter class to write your inventory to a text file. This means for each process in your array, print the name, quantity, price, and upc (all on different lines I recommend). You can test to see if this is working correctly by looking at the at the text file you tried creating. If you are sure the method is working, try implementing the loadlnventoryFromFile method. This method will instead read in all the inventory information (if the file exists!) into the programs array. Test this method by running the program and immediately running this file. Then try to print out the inventory Milestone 6- Create loop interface with user (10 pts) This is essentially the final milestone. This will go inside main. Each time the loop iterates (loops) you will display a menu to the user (see the example of the program running I provided below) and allow them to enter a choice. Based on the choice you will perform that action (which associates directly to a method for the most part). If the user enters in 5 (exit) the loop will stop looping and the program will end. To figure out which of the 5 options the user chose you should use a SWITCH structure (not a bunch of if statements). Some of the options 1 and 2 will require you to get more information from the user. 5. 6. Here is an example of the programming running once Problems Javadoc Declaration Console InventoryTrackerinterface [Java cation 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Enter the new items name Banana Enter the new items quantity 52 Enter the new items price 5.55 Enter the new items upc 123456 1 Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Enter the new items name Tomatoe Enter the new items quantity Enter the new items price 67 Enter the new items upc 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Enter the new items name Pepper Enter the new items quantity 500 Enter the new items price 25 Enter the new items upc 000223 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Which item would you like info for? [e-2] Name: Quantity: 555 Price: 0.67 UPC: 1 Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Tomatoe Inventory Saved 1 Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit Goodbye! And an example of it running again after saving and exiting in the previous example.... &L Problems @ Javadock > DeclarationConsole Inventory Trackerinterface [Java Application 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit 2 No items in inventory 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit 4 Inventory Loaded 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit 2 Which item would you like info for? [0-2] 1 Name: Quantity: 555 Tomatoe Price: 0.67 UPC: 1. Add an item to the inventory 2. Get an items info 3. Save Inventory to file 4. Load Inventory from file 5. Exit 5 Goodbye! Additional points: Comments: 30 points