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

Practice Problem - Java Problem: You have been approached by the local convenien

ID: 3700564 • Letter: P

Question

Practice Problem - Java Problem: You have been approached by the local convenience store to assist them with their inventory. They sell about 100 different products and currently have no way to keep track of the inventory. They have asked that you show them a sample of how you plan to solve the problem. You have decided that if would be best if you could create a class for each product they sell, and then use a main program to store an array of all products. You realize that there are some common values to all of the products sold. For example, all products have a UPC code for identification, product name, manufacturer, quantity in inventory, wholesale price, and a retail price. The management considers it very important that they can quickly know how many items they currently have for sale. This includes the total of all inventories for all products; as well just knowing how many different products the store carries (requires a static instance variable). What methods do you consider important to the problem? Make a list of instance variables and methods on another piece of paper. You decide that it would be helpful if you also created a few extended classes to show management. This will show them how quick and easy it will be to add new items to inventory. Pick two items that could be added to inventory in a convenience store and create the extended classes. Create two subclasses of products milk and ice cream. For milk, include the variables of size(Gallong, half gallont), and what kind of milk(Whole milk, 1% milk, 2% milk, skim milk) For ice cream, include the variable of size(pint, 1/2 pint, ounces), and what flavor(Vanilla, Chocolate, Strawberry). Create a driver class that an array of product: product[] inventory = new product[100];. This should be a menu driven program that should include loops, counters, and the following methods of: addToInventory removeFromInventory compareTo

Explanation / Answer

Solution:

code:

Product,java

public class Product {

//instance members

private String upcCode;

private String productName;

private String manufacturer;

private String quantityInInventory;

private double wholesalePrice;

private double retailPrice;

//default constructor

Product(){

}

//parameterized constructor

Product(String upcCode, String productName, String manufacturer,

String quantityInInventory, double wholesalePrice,

double retailPrice) {

this.upcCode = upcCode;

this.productName = productName;

this.manufacturer = manufacturer;

this.quantityInInventory = quantityInInventory;

this.wholesalePrice = wholesalePrice;

this.retailPrice = retailPrice;

}

public String toString() {

return "Upc Code ="+ upcCode+", Product Name ="+ productName+", Manufacturer = "+manufacturer+", Quantity InInventory = "+quantityInInventory+", Retail Price = "+retailPrice;

}

public String getUpcCode() {

return upcCode;

}

public void setUpcCode(String upcCode) {

this.upcCode = upcCode;

}

public String getProductName() {

return productName;

}

public void setProductName(String productName) {

this.productName = productName;

}

public String getManufacturer() {

return manufacturer;

}

public void setManufacturer(String manufacturer) {

this.manufacturer = manufacturer;

}

public String getQuantityInInventory() {

return quantityInInventory;

}

public void setQuantityInInventory(String quantityInInventory) {

this.quantityInInventory = quantityInInventory;

}

public double getWholesalePrice() {

return wholesalePrice;

}

public void setWholesalePrice(double wholesalePrice) {

this.wholesalePrice = wholesalePrice;

}

public double getRetailPrice() {

return retailPrice;

}

public void setRetailPrice(double retailPrice) {

this.retailPrice = retailPrice;

}

}//class Product ends

DriverProduct.java

import java.util.ArrayList;

public class DriverProduct {

//maintain static names of items

static String ITEM1="PERFUME";

static String ITEM2="SOAP";

public static void main(String[] args) {

ArrayList al=new ArrayList();

/*

*

* created two items using product class like this we can add n number of items

* To the inventory in a convenience store

*/

Product product1=new Product("AA101", ITEM1, "AXE", "2019", 100.89, 99.76);

Product product2=new Product("BB101", ITEM2, "SANDLE", "2020", 300.89, 180.76);

al.add(product1);

System.out.println(al);

al.add(product2);

System.out.println(al);

}//driver main method ends

}//class DriverProduct ends

Output:

[Upc Code =AA101, Product Name =PERFUME, Manufacturer = AXE, Quantity InInventory = 2019, Retail Price = 99.76]
[Upc Code =AA101, Product Name =PERFUME, Manufacturer = AXE, Quantity InInventory = 2019, Retail Price = 99.76, Upc Code =BB101, Product Name =SOAP, Manufacturer = SANDLE, Quantity InInventory = 2020, Retail Price = 180.76]

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