Warehouse.java, a project about hash table
Budget: $2 – $8 USD
addToEnd
Write a method in your Warehouse class that takes in a new product id, name, stock, day and initial demand, and adds a new Product object to the end of the correct sector.
The sector index you add to should be the last digit of the given product id.
The initial date of last purchase of your new Product should be set to the current day (which is passed in).
The input file will be formatted as follows:
An integer n representing the number of products to add
n lines, each containing the following in this order (space separated):
The current day
The product ID
The product name (Guaranteed to not contain spaces)
The initial item stock
The initial item demand
Fill in the AddProduct.java file to read from args[0] and write to args[1]. Create a new Warehouse object, then add each Product from the input file to your warehouse using the addProduct() method (and NOT the addToEnd() method. This will help with testing later). Finally, you can simply print out your Warehouse object to your output file. For example, if your Warehouse object is named w, call StdOut.println(w).
The output will be a text representation of your warehouse, showing the Products in each sector, specifically their names, stocks and popularities.
Here is the correct “addtoend.out” file obtained from running the AddProduct.java file with the command line arguments “addtoend.in” and “addtoend.out” in that order.
fixHeap
Your current addProduct is fine, but as of now it just appends to the end of the sector. We want to maintain a min-heap structure based on popularity at all times.
Write a method in your Warehouse class that takes in the id of a product which was just added to the end of its Sector, and fixes the heap structure of that Sector.
Look into the Sector class to see what methods are provided to you. You do NOT have to implement all the heap operations from scratch.
fixHeap does NOT call the addToEnd() method. It is assumed that the method has already been called, as can be seen in the template method for addProduct().
The input file format is exactly the same as addToEnd.
You do not have to change the AddProduct.java class in any way to test your updated addProduct() method.
The output file format is exactly the same as addToEnd.
Here is the correct “fixheap.out” file obtained from running the AddProduct.java file with the command line arguments “fixheap.in” and “fixheap.out” in that order.
evictIfNeeded
Your current addProduct() works fine until one of the sectors goes over capacity. We want to delete the least popular element when we are trying to add in a new one, so we can continue adding new products.
Write a method in your Warehouse class that takes in the id of a product we want to add (hasn’t been added yet), and makes room for it in the correct Sector. It will implement our deleteMin() algorithm from class which deletes from the min heap.
The method ONLY performs this operation if necessary. In other words, it does nothing UNLESS the sector we want to insert into is currently at full capacity (has 5 products already).
The popularity of the item to be inserted is irrelevant. This method still removes the least popular item in a full capacity sector, even if we’re about to insert an even less popular new item.
Look into the Sector class to see what methods are provided to you. You do NOT have to implement all the heap operations from scratch.
The input file format is exactly the same as addToEnd.
You do not have to change the AddProduct.java class in any way to test your updated addProduct() method.
The output file format is exactly the same as addToEnd.
Here is the correct “addproduct.out” file obtained from running the AddProduct.java file with the command line arguments “addproduct.in” and “addproduct.out” in that order.
Write a method in your Warehouse class that takes in a new product id, name, stock, day and initial demand, and adds a new Product object to the end of the correct sector.
The sector index you add to should be the last digit of the given product id.
The initial date of last purchase of your new Product should be set to the current day (which is passed in).
The input file will be formatted as follows:
An integer n representing the number of products to add
n lines, each containing the following in this order (space separated):
The current day
The product ID
The product name (Guaranteed to not contain spaces)
The initial item stock
The initial item demand
Fill in the AddProduct.java file to read from args[0] and write to args[1]. Create a new Warehouse object, then add each Product from the input file to your warehouse using the addProduct() method (and NOT the addToEnd() method. This will help with testing later). Finally, you can simply print out your Warehouse object to your output file. For example, if your Warehouse object is named w, call StdOut.println(w).
The output will be a text representation of your warehouse, showing the Products in each sector, specifically their names, stocks and popularities.
Here is the correct “addtoend.out” file obtained from running the AddProduct.java file with the command line arguments “addtoend.in” and “addtoend.out” in that order.
fixHeap
Your current addProduct is fine, but as of now it just appends to the end of the sector. We want to maintain a min-heap structure based on popularity at all times.
Write a method in your Warehouse class that takes in the id of a product which was just added to the end of its Sector, and fixes the heap structure of that Sector.
Look into the Sector class to see what methods are provided to you. You do NOT have to implement all the heap operations from scratch.
fixHeap does NOT call the addToEnd() method. It is assumed that the method has already been called, as can be seen in the template method for addProduct().
The input file format is exactly the same as addToEnd.
You do not have to change the AddProduct.java class in any way to test your updated addProduct() method.
The output file format is exactly the same as addToEnd.
Here is the correct “fixheap.out” file obtained from running the AddProduct.java file with the command line arguments “fixheap.in” and “fixheap.out” in that order.
evictIfNeeded
Your current addProduct() works fine until one of the sectors goes over capacity. We want to delete the least popular element when we are trying to add in a new one, so we can continue adding new products.
Write a method in your Warehouse class that takes in the id of a product we want to add (hasn’t been added yet), and makes room for it in the correct Sector. It will implement our deleteMin() algorithm from class which deletes from the min heap.
The method ONLY performs this operation if necessary. In other words, it does nothing UNLESS the sector we want to insert into is currently at full capacity (has 5 products already).
The popularity of the item to be inserted is irrelevant. This method still removes the least popular item in a full capacity sector, even if we’re about to insert an even less popular new item.
Look into the Sector class to see what methods are provided to you. You do NOT have to implement all the heap operations from scratch.
The input file format is exactly the same as addToEnd.
You do not have to change the AddProduct.java class in any way to test your updated addProduct() method.
The output file format is exactly the same as addToEnd.
Here is the correct “addproduct.out” file obtained from running the AddProduct.java file with the command line arguments “addproduct.in” and “addproduct.out” in that order.