Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSc 2720 Data Structures: Assignment 3 How to Submit Turn the java files in Folder Assignment 3 in iCollege no later than 11:59 p.m. on

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
CSc 2720 Data Structures: Assignment 3 How to Submit Turn the java files in Folder Assignment 3 in iCollege no later than 11:59 p.m. on 03/17/2018 Note: Handle all the possible exceptions regarding insertion, deletion or update operations in the list using the given ProductException class . Requirements: You have a new project in your company and your dient is a small shopkeeper that needs to manage the shop inventory. Your job is to design and implement ProductNode and Productinventory classes that manage the inventory using a linked List ADT. The specifications of the two classes are as follows: ProductNode Class For each product, you should store the following info: 1. Product Name (i.e. "Apple iphone 7 plus 32gb rose gold", may contain spaces in it, not unique) 2. Locator (string used to physically locate product, not unique) 3. Quantity (how many of this product in stock, greater than or equal to 0) 4. Price (in dollars and cents, greater than 0) Note: For a given product, the product name AND locator together must be unique. So you may have two entries for "iPhone 5c" if one has "box3" for the locator and the other has "shelf12" You should implement two constructors: A constructor that takes no arguments (quantity and price are initialized to 0, product name and locator are initialized to empty strings) A constructor that takes a value for each of the four-member variables. Productinventory Class showinventory: displays a listing of the product inventory to the screen, one product entry per line. Output locator, then quantity, then price, then product name getTotalQuantity: returns the total number of units of all of the products in the inventory removeMaximum: finds the maximum product in the list based in the quantity. It removes the node of the maximum from the list and returns a pointer to this node. sortinventory: reorders the products in the list based on their quantity, using removeMaximum. Here is the algorithm you must use for implementing the sort function. It is a form of the selection sort. It selects the next (maximum) element from the current list and removes its node from the current list, and then inserts the node at the front of a new list (pointed to by a temporary pointer). When finished, it makes the old head pointer point to the new list. "inventoryHead" is the head pointer and while inventoryHead is not empty find the maximum product in inventoryHead list and remove it (i.e. call removeMaximum) add the maximum node to the front of a new temporary list end and finally make inventoryHead point to the new temporary list. addProduct: takes a product and adds it to the inventory. If a product with the same name and locator already exists in the inventory or if the quantity or price are invalid, the function throws a ProductException removeProduct:takes a product name and locator and removes any matching product from the inventory countProduct: since the same product can exist in the inventory with different locators. The function should take the name of a given product, traverse the inventory list and count the quantity of the same product. countNeededQuantity: the store keeper needs to order products in the inventory to avoid any future shortage. The function should take the name of the product and the desired quantity of a given product as an argument. The function calls countProduct to deduce the needed quantity ProductNode Class Template public class ProductNode ( ProductNode next; //Constructor # 1 ProductNode)( // Intialize other variables here next- null; //constructor # 2 .ProductNode Class Template public class ProductInventory ProductNode inventoryHead new ProductNode(); public void showInventoryO public int getTotalQuantity)( return e; public ProductNode removeMaximum)( return null; public void sortInventoryO( public void addProduct (String productName, String locator, int quantity, float price)( public void removeProduct (String productName, String locator) public int countProduct(String productName)( return e; public int countNeededQuantity (String productName, int neededQuantity)( return e class ProductException extends RuntimeException public ProductException(String s) super(s) II end ProductException )// End ProductInventory .InventoryTester Class Template public class InventoryTester public static void main(String[] args)( ProductInventory inventory- new ProductInventory); // Add Products to inventory inventory.addProduct ("Apple iphone 7 plus 32gb rose gold", "box256",1, 699.8e) inventory. addProduct ("Apple iphone 7 plus 32gb rose gold, "shelf4", 4, 699.80) inventory.addProduct("Apple macbook pro "box15", 2, 1580.87); inventory.addProduct ("Del1 Monitor", "shelf1, 12, 221.54); // Show inventory inventory. showInventory Product Name Locator Quantity Price Apple iphone 7 plus 32gb rose gold box256 Apple iphone 7 plus 32gb rose gold shelf4 Apple macbook pro Dell Monitor 10 699.80 699.80 1580.87 221.54 box14 shelf10 12 // Sort Products in inventory inventory.sortInventory // Show inventory After sorting inventory. showInventory Product Name LocatorQantity Price Dell Monitor Apple iphone 7 plus 32gb rose gold box256 Apple iphone 7 plus 32gb rose gold shelf4 Apple macbook pro 221.54 699.80 699.88 1580.87 shelf18 12 box14 System.out.println(inventory.countProduct( "Apple iphone 7 plus 32gb rose gold)); // Should return 14 System.out.println(inventory.countNeededQuantity("De11 Monitor", 15) Should return 3 inventory.removeMaximum) inventory.removeProduct ("Apple iphone 7 plus 32gb rose gold, "shelf4"); System.out.println(inventory.getTotalQuantity)) IIShould return 12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions