Question

Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If...

Goal:   Manage the inventory of objects sold in an online or brick and mortar store.

If you can't implement all of the features of Project described in this document, implement what you can. Start by implementing the StockItem class, and its derived classes. Then add in the InventoryManager class later. In each case, the test files must be in separate classes.

UML Diagram: Use Violet or other drawing software to draw the UML diagrams of each class that you use in your Project submission. Show the relationships between these classes, e. g., inheritance and composition.

Testing: Write JUnit tests using assertEquals to test each method of the StockItem class and your classes derived from StockItem. In the setup method of a Unit Test Case, enter and save at least 3 objects from each of the classes derived from StockItem. Test each method in the classes that you use in your Project 4 submission. Don't write JUnit tests for your Inventory manager class. Instead, write traditional tests in a separate class that has a main method.

Details:

Before writing any source code, draw the UML diagram using Violet or some other drawing system.

Implement these classes: (1) StockItem, (2) InventoryManager, (3, 4, ...) at least two classes derived from StockItem.

StockItem   Instance Variables: _id _description _price _quantity

Derived Classes (at least two) Base class: StockItem Instance Variables: at least two for each class.

For the StockItem class and each of the classes derived from StockItem, include a noarg constructor, a parameterized constructor, getters, and atoString method.

Include setters for _price and _quantity in the StockItem class.

InventoryManager   Instance Variable: _col (ArrayList<StockItem> collection)
Methods: noarg constructor, add (add StockItem object to _col), displayAll (return array list of all items in _col, sorted by description), find (return all objects with specified substring in description, sorted by description), getItem (get item with specified id), load (deserialize _col from .ser file), removeItem (remove item), save (serialize col to .ser file).


Feel free to use Eclipse to generate your constructors, getters, setters, and toString methods for your StockItem and derived classes.

The toString methods of the derived classes of StockItem return the output that is shown for InventoryManager display, displayAll, get, and find methods.

Keep a log of all getItem, and find requests so that the store staff can analyze later to get ideas for how to stock items in the store. Each log entry should include a time stamp, the method call, and the arguments passed to it, and toString output of the objects returned.

Implement the Comparable interface for the StockItem class so that the items in the InventoryManager collection can be sorted before being returned.

The InventoryManager class should implement the Serializable interface so that its collection (ArrayList or HashMap) can be serialized to or deserialized from a .ser file.

Optional: instead of using an ArrayList, consider using a HashMap collection to hold the LibraryItem objects. This makes the InventoryManager methods display more quickly if the store has many items in stock.

Include Javadoc comments in each of your classes. When your project is finished, run the javadoc utility and copy the generated html files to a separate folder named javadoc in your project zipfile. Use Javadoc comments at the beginning of classes, constructors, and methods.

Format of Javadoc comment before a class:

/**
 * Short description of class
 *
 * @author   Stan Smith 
 * @version  1.6 2/26/17     
 */
public class MyClass {
    // class body
}

Format of a Javadoc comment before a constructor or method:

/**
 * Short one line description.                  
 * <p>
 * Longer description. If there were any,
 * it would be here.
 * <p> 
 * And even more explanations to follow in 
 * consecutive paragraphs separated by HTML 
 * paragraph breaks.
 * <p>
 * @param  parameter description.   
 * @return return value description
 * @throws description of exceptions thrown
 */
public int methodName(...) {
    // method body }

Format of a Javadoc comment before a public field:

/**
 * Description of variable here.
 */
public final int constantName = 1234;

Homework Answers

Answer #1

public class StockItem {

   // declaration of instance variables
   protected int id;
   protected String description;
   protected double price;
   protected double quantity;

   /**
   * constructor for no-argument constructor
   */
   public StockItem() {

       id = 0;
       description = null;
       price = 0;
       quantity = 0;
   }

   /**
   * @param id
   * @param description
   * @param price
   * @param quantity
   */
   public StockItem(int id, String description, double price, double quantity) {
       this.id = id;
       this.description = description;
       this.price = price;
       this.quantity = quantity;
   }

   /**
   * @return the id
   */
   public int getId() {
       return id;
   }

   /**
   * @param id
   * the id to set
   */
   public void setId(int id) {
       this.id = id;
   }

   /**
   * @return the description
   */
   public String getDescription() {
       return description;
   }

   /**
   * @param description
   * the description to set
   */
   public void setDescription(String description) {
       this.description = description;
   }

   /**
   * @return the price
   */
   public double getPrice() {
       return price;
   }

   /**
   * @param price
   * the price to set
   */
   public void setPrice(double price) {
       this.price = price;
   }

   /**
   * @return the quantity
   */
   public double getQuantity() {
       return quantity;
   }

   /**
   * @param quantity
   * the quantity to set
   */
   public void setQuantity(double quantity) {
       this.quantity = quantity;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#hashCode()
   */
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result
               + ((description == null) ? 0 : description.hashCode());
       result = prime * result + id;
       long temp;
       temp = Double.doubleToLongBits(price);
       result = prime * result + (int) (temp ^ (temp >>> 32));
       temp = Double.doubleToLongBits(quantity);
       result = prime * result + (int) (temp ^ (temp >>> 32));
       return result;
   }

   /*
   * (non-Javadoc)
   *
   * @see to check stockitem#equals(another stock item)
   */
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       StockItem other = (StockItem) obj;
       if (description == null) {
           if (other.description != null)
               return false;
       } else if (!description.equals(other.description))
           return false;
       if (id != other.id)
           return false;
       if (Double.doubleToLongBits(price) != Double
               .doubleToLongBits(other.price))
           return false;
       if (Double.doubleToLongBits(quantity) != Double
               .doubleToLongBits(other.quantity))
           return false;
       return true;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "StockItem [id=" + id + ", description=" + description
               + ", price=" + price + ", quantity=" + quantity + "]";
   }

}

****************************************************************************************

public class Mobile extends StockItem {

   protected String brandName;
   protected int ramCapacity;

   /**
   * @param brandName
   * @param ramCapacity
   */

   /**
   * @return the brandName
   */
   public String getBrandName() {
       return brandName;
   }

   /**
   * @param id
   * @param description
   * @param price
   * @param quantity
   * @param brandName
   * @param ramCapacity
   */
   public Mobile(int id, String description, double price, double quantity,
           String brandName, int ramCapacity) {
       super(id, description, price, quantity);
       this.brandName = brandName;
       this.ramCapacity = ramCapacity;
   }

   /**
   * @param brandName
   * the brandName to set
   */
   public void setBrandName(String brandName) {
       this.brandName = brandName;
   }

   /**
   * @return the ramCapacity
   */
   public int getRamCapacity() {
       return ramCapacity;
   }

   /**
   * @param ramCapacity
   * the ramCapacity to set
   */
   public void setRamCapacity(int ramCapacity) {
       this.ramCapacity = ramCapacity;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#hashCode()
   */
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = super.hashCode();
       result = prime * result
               + ((brandName == null) ? 0 : brandName.hashCode());
       result = prime * result + ramCapacity;
       return result;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#equals(java.lang.Object)
   */
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (!super.equals(obj))
           return false;
       if (getClass() != obj.getClass())
           return false;
       Mobile other = (Mobile) obj;
       if (brandName == null) {
           if (other.brandName != null)
               return false;
       } else if (!brandName.equals(other.brandName))
           return false;
       if (ramCapacity != other.ramCapacity)
           return false;
       return true;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Mobile [brandName=" + brandName + ", ramCapacity="
               + ramCapacity + ", id=" + id + ", description=" + description
               + ", price=" + price + ", quantity=" + quantity + "]";
   }

}

*********************************************************************************************************

public class book extends StockItem {

   protected String bookname;
   protected String authorname;

   /**
   * @param bookname
   * @param authorname
   */
   /**
   *
   *
   * @return the bookname
   */
   public String getBookname() {
       return bookname;
   }

   /**
   * @param id
   * @param description
   * @param price
   * @param quantity
   * @param bookname
   * @param authorname
   */
   public book(int id, String description, double price, double quantity,
           String bookname, String authorname) {
       super(id, description, price, quantity);
       this.bookname = bookname;
       this.authorname = authorname;
   }

   /**
   * @param bookname
   * the bookname to set
   */
   public void setBookname(String bookname) {
       this.bookname = bookname;
   }

   /**
   * @return the authorname
   */
   public String getAuthorname() {
       return authorname;
   }

   /**
   * @param authorname
   * the authorname to set
   */
   public void setAuthorname(String authorname) {
       this.authorname = authorname;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#hashCode()
   */
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = super.hashCode();
       result = prime * result
               + ((authorname == null) ? 0 : authorname.hashCode());
       result = prime * result
               + ((bookname == null) ? 0 : bookname.hashCode());
       return result;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#equals(java.lang.Object)
   */
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (!super.equals(obj))
           return false;
       if (getClass() != obj.getClass())
           return false;
       book other = (book) obj;
       if (authorname == null) {
           if (other.authorname != null)
               return false;
       } else if (!authorname.equals(other.authorname))
           return false;
       if (bookname == null) {
           if (other.bookname != null)
               return false;
       } else if (!bookname.equals(other.bookname))
           return false;
       return true;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "book [bookname=" + bookname + ", authorname=" + authorname
               + ", id=" + id + ", description=" + description + ", price="
               + price + ", quantity=" + quantity + "]";
   }

}

**************************************************************************************

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class InventoryManager implements Serializable {

   private List<StockItem> items;

   /**
   * for create no orgument constructor
   */
   public InventoryManager() {

       items = new ArrayList<StockItem>();
   }

   public void add(StockItem item) {
       items.add(item);
   }

   public void display() {
       Collections.sort(items, new Comparator<StockItem>() {

           @Override
           public int compare(StockItem o1, StockItem o2) {
               // TODO Auto-generated method stub
               return o1.description.compareTo(o2.description);
           }
       });

       for (StockItem item : items) {
           System.out.println(item);
       }
   }

   public void getItem(int id) {

       for (StockItem item : items) {
           if (item.id == id) {
System.out.println(item);
           }
       }

   }

   public int removeItem(StockItem item) {
       int count = 0;
       for (StockItem item1 : items) {
           if (item.equals(item1)) {
               items.remove(item);
               ++count;
           }
       }
       return count;
   }

   public void find(String substring) {
       for (StockItem item : items) {
           if (item.getDescription().contains(substring)) {
               System.out.println(item);
           }
       }
   }
}

******************************************************

public class Demo {

   public static void main(String[] args) {
       StockItem item = new Mobile(1, "selfieexpert", 14000, 1, "samsung", 256);

       StockItem item1 = new book(2, "to achieve goals", 4000, 1,
               "dreaminlife", "marktwain");

       InventoryManager manager = new InventoryManager();

       manager.add(item);
       manager.add(item1);
       manager.display();
       manager.find("expert");

manager.getItem(1);

   }

}

output

Mobile [brandName=samsung, ramCapacity=256, id=1, description=selfieexpert, price=14000.0, quantity=1.0]
book [bookname=dreaminlife, authorname=marktwain, id=2, description=to achieve goals, price=4000.0, quantity=1.0]
Mobile [brandName=samsung, ramCapacity=256, id=1, description=selfieexpert, price=14000.0, quantity=1.0]
book [bookname=dreaminlife, authorname=marktwain, id=2, description=to achieve goals, price=4000.0, quantity=1.0]

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The main goal is to implement two recursive methods, each is built to manipulate linked data...
The main goal is to implement two recursive methods, each is built to manipulate linked data structures. To host these methods you also have to define two utterly simplified node classes. 1.) Add a class named BinaryNode to the project. This class supports the linked representation of binary trees. However, for the BinaryNode class Generic implementation not needed, the nodes will store integer values The standard methods will not be needed in this exercise except the constructor 2.) Add a...
How to use C++ figure this question? Collection and Sorted Collection An array is great for...
How to use C++ figure this question? Collection and Sorted Collection An array is great for storing a list of values. However, one challenge when working with arrays is they have a fixed size. If you declare an array of size 10 and later need to actually store 11 elements you have to create a new array and copy everything over. C++ (and other langauges) create classes that handle this and other operations behind the scenes. In this assignment, we...
Your solutions will be graded on the bassis of originality, completeness, and compliance to the object...
Your solutions will be graded on the bassis of originality, completeness, and compliance to the object oriented programming concepts. No Java code is required for this section. Question 1:   Assume you are required to write an object oriented program for purchasing household items for a new house. Identify at least five classes of household items such as decoration items, washroom items etc. Each of these classes must have at least two types of items. Draw a UML class diagram identifying...
Lists are members of a general category of abstract data types (ADTs) called containers (i.e., objects...
Lists are members of a general category of abstract data types (ADTs) called containers (i.e., objects whose purpose is to hold other objects). A list is a collection of items having the following defining characteristics: Homogeneity: All the items are of the same type. Linearity: Each item has a unique predecessor (except the first) and a unique successor (except the last). Variable Length: The number of items can vary over time. Order: Items may be ordered (i.e., as in a...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character)...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character) in a video game has some basic data that belongs to all entities in a game. All NPCs have a name, which is a String, health, which is an integer, and a description, which is a String. NPCs have accessor methods for each of their instance variables. NPCs also have an act() method, which is void; however, since there are no true NPCs in...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character)...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character) in a video game has some basic data that belongs to all entities in a game. All NPCs have a name, which is a String, health, which is an integer, and a description, which is a String. NPCs have accessor methods for each of their instance variables. NPCs also have an act() method, which is void; however, since there are no true NPCs in...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of...
This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). Extend...
This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). Extend the ItemToPurchase class per the following specifications              Private fields string itemDescription - Initialized in default constructor to "none" Parameterized constructor to assign item name, item description, item price, and itemquantity (default values of 0).             Public instance member methods setDescription() mutator & getDescription() accessor (2 pts) printItemCost() - Outputs the item name followed by the quantity, price, and subtotal printItemDescription() - Outputs the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT