Answer to Question #243684 in Java | JSP | JSF for ssmi

Question #243684

Create a class called Storage that a hardware store might use to the actual storage of the * store. * A storage should include the following information as instance variables: * a map of all the items that the storage has (type HashMap). The key * is item’s description * In addition, provide a method named getItemQuantity(String description) that returns the * item that is being searched if there is any in storage. If the item is found in storage * returns the ItemQuantity otherwise returns null * Provide a method addItemQuantity(Item, Number) that saves input items to the storage. This * method should take as inputs the Item and the quantity of item. It should be a void method and should add the item to storage map 


1
Expert's answer
2021-09-28T11:42:46-0400
import java.util.HashMap;

public class Storage {
    private HashMap<String, Item> storage;

    public Storage() {
        storage = new HashMap<>();
    }

    public Integer getItemQuantity(String description) {
        Item item = storage.get(description);
        if (item == null) {
            return null;
        }
        return item.getQuantity();
    }

    public void addItemQuantity(Item item, Integer quantity) {
        item.setQuantity(quantity);
        storage.put(item.getDescription(), item);
    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS