HW5 Inventory Catalog HOMEWORK SUMMARY IN JAVA How many item

HW5: Inventory Catalog

HOMEWORK SUMMARY

IN JAVA

How many items do Amazon.com sell? As of December 2015, in the US, almost half a billion different items (link). How does it keep track of all those items? Wait – back track. What does it have to keep track for all those items? Sure there are the obvious ones such as name of the product, price, description, and quantity. How about item location (which warehouse, where in the warehouse, etc.)? Supplier/Seller? Expiration Date? Variations of the same product? Now imagine trying to use simple variables to store all the information needed for 500 million items. How many variables would you need? And what if you want to add a new metadata? Fortunately, you now understand the basics of OOP (Object-Oriented Programming).

Aside: Databases are used as the eventual storage of all these data. However, data stored in databases must be processed by programs to be meaningful, so there’s still the challenge of being able to work with all the relevant data for any given item. OOP makes it easier to work with large sets of data by both providing some context on the data as well as provide common actions to be performed on the data.

Skills Expected

All the skills from previous Assignment(s)

Class objects and design

Assignment Description

You will write three Class objects (and subsequently submit three .java files):

Item

ItemCatalog

ItemCatalogDriver

Class Design: Item

The Item class is intended to be an abstract and simplified representation of an item for sale.

Data to store:

Name

Description

Price (let’s make it simple and say “each”)

Quantity

Available actions

Display Item – this will print out the item to the console similar to the following: Apple. A fruit known for its ability to keep people healthy – supposedly. $0.69 each. Quantity: 112 available for sale.

Purchase Item – this will take in as argument an integer representing the number of items to purchase. You need to verify that this is a valid quantity (what is “valid” here?) and update quantity accordingly.

Restock Item – this will take in as argument an integer representing the number of items to “restock.” You need to verify that this is a valid quantity (what is “valid” here?) and update quantity accordingly.

Class Design: ItemCatalog

The ItemCatalog class is intended to be an abstract and simplified representation of a catalog of items for sale.

Data to store:

An array of items – “pre-populate” this with at least three different Item objects.

Available actions:

Display Items – this will print out all the items in your array sequentially. Call the “Display Item” action for each item.

Add Item – this will add a new Item to the array of items.

Class Design: ItemCatalogDriver

The textbook defines a “driver program” as “A program that does nothing but test a method.” In other words, ItemCatalogDriver will be used to test the methods you implemented for the ItemCatalog class, which will result in testing both the Item and ItemCatalog classes, by extension.

Write a main method that does the following:

Create an instance of an Item.

Display the Item.

Purchase the Item (and call Display again to make sure it purchased correctly).

Restock the Item (and call Display again to make sure it restocked correctly).

Create an instance of an ItemCatalog.

Display Items in the catalog.

Add the above Item into the catalog (and call Display again to make sure it was added correctly).

Purchase an Item from inside the catalog (and call Display again to make sure it was purchased correctly).

Grading Criteria

Item class object

[1 point] Correct Class definition/syntax

[2points] Correctlystoresallrequireddata (“Datatostore” section)

[1point] DisplayItemmethod

[2points] PurchaseItem method(including error checking and updating quantity)

[2 points] Restock Item method (including error checking and updating quantity)

ItemCatalog class object

[1 point] Correct Class definition/syntax

[1 point] Three sample items

[2 points] Correctly stores Items in an array

[1point] Add Item method

ItemCatalogDriver class object

[1point] Create Item

[1point] Display Item

[1point] Purchase Item

[1point] Restock Item

[1point] Create ItemCatalog

[1point] Display Items

[1point] Add Item

[2points] Purchase Item (from inside catalog)

[1 point] Method JavaDoc: description, @param, @return

[1 Point] Descriptive variable names

[1 Point] Appropriate class header comment block

Solution

Item.java

public class Item{
    public String name, description;
    public double price;
    public int quantity;

    public Item(String name, String description, double price, int quantity){
        this.name = name;
        this.description = description;
        this.price = price;
        this.quantity = quantity;
    }

    public void DisplayItem(){
        System.out.println(name+\". \"+description+\". \"+price+\" each. Quantity: \"+quantity+\" available for sale\");
    }

    public void PurchaseItem(int quant){
        if(quant<quantity){
            quantity -= quant;
        }

        else{
            System.out.println(\"We don\'t have that much in stock.\");
        }
    }

    public void RestockItem(int quant){
        if(quant>0){
            quantity += quant;
        }
        else{
            System.out.println(\"Enter a positive quantity for restock.\");
        }
    }

}

ItemCatalog.java

import java.util.ArrayList;
public class ItemCatalog{
    public ArrayList<Item> items;

    public ItemCatalog(){
        items = new ArrayList<Item>();
        items.add(new Item(\"Apple\", \"Fruit\", 5.25, 500));
        items.add(new Item(\"Potato\", \"Vegetable\", 2.25, 200));
        items.add(new Item(\"Guava\", \"Fruit\", 3.25, 500));
    }

    public void DisplayItems(){
        for (Item item: items){
            item.DisplayItem();
        }
    }

    public void AddItem(Item item){
        items.add(item);
    }
}

ItemCatalogDriver.java

public class ItemCatalogDriver{

    public static void main(String[] args) {
        Item item = new Item(\"Orange\", \"Fruit\", 5.25, 500);
        item.DisplayItem();
        item.PurchaseItem(25);
        item.DisplayItem();
        item.RestockItem(200);
        item.DisplayItem();

        ItemCatalog items = new ItemCatalog();
        items.DisplayItems();
        items.AddItem(item);
        items.DisplayItems();
    }
}

HW5: Inventory Catalog HOMEWORK SUMMARY IN JAVA How many items do Amazon.com sell? As of December 2015, in the US, almost half a billion different items (link).
HW5: Inventory Catalog HOMEWORK SUMMARY IN JAVA How many items do Amazon.com sell? As of December 2015, in the US, almost half a billion different items (link).
HW5: Inventory Catalog HOMEWORK SUMMARY IN JAVA How many items do Amazon.com sell? As of December 2015, in the US, almost half a billion different items (link).
HW5: Inventory Catalog HOMEWORK SUMMARY IN JAVA How many items do Amazon.com sell? As of December 2015, in the US, almost half a billion different items (link).

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site