Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3797177 • Letter: G

Question

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:

Format of a Javadoc comment before a constructor or method:

Format of a Javadoc comment before a public field:

Explanation / Answer

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]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote