So the assignment is to Modify the Inventory Program by creating a subclass of the product class that uses an additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product. I finally got the first part to work write but I am struggling with even getting started on the subclass.
package InventoryProgram;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
/**
*
* @author kyle
*/
public class ProductInventory2 {
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US);
ArrayList<Product> myItemInventory = new ArrayList<Product>();
System.out.println();
System.out.println();
System.out.println();
System.out.println("Welceome to Warehouse Inventory");
System.out.println();
System.out.println("Here is a list of Iventoried Items");
myItemInventory.add(new Product("Poles", 3,75.00f, 4));
myItemInventory.add(new Product("Transformers", 1,96.75f, 10));
myItemInventory.add(new Product("CutOuts", 2, 36.00f, 100));
myItemInventory.add(new Product("LED LIGHT", 4, 15.00f, 25));
Collections.sort(myItemInventory);
System.out.println();
System.out.println();
System.out.println("Product Information");
double totalInventoryValue = 0;
for (Product item : myItemInventory) {
System.out.println(item.toString());
totalInventoryValue = totalInventoryValue + item.getTotalValue();
}
System.out.println(currency.format(totalInventoryValue));
System.out.println();
System.out.println();
System.out.println("Exiting the Warehouse Inventory");
System.out.println();
System.out.println();
}
public double getTotalValue() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
class Product implements Comparable<Product> {
protected String ItemName;
protected int ItemNumber;
protected int ItemsinStock;
protected float ItemPrice;
double restockfee;
public Product(String ItemName, int ItemNumber, int ItemsinStock, float ItemPrice){
}
Product() {
setName("unknown");
setNumber(-1);
setPrice(0);
setItemsinStock(0);
}
Product(String pItemName, int pItemNumber, float pItemPrice,
int pItemsinStock) {
setName(pItemName);
setNumber(pItemNumber);
setPrice(pItemPrice);
setItemsinStock(pItemsinStock);
}
@Override
public int compareTo(Product pAnotherProduct) throws ClassCastException {
if (this.getNumber() > pAnotherProduct.getNumber())
return 1;
else
return -1;
}
public void setName(String pProductName) {
ItemName = pProductName;
}
public void setNumber(int pProductNumber) {
ItemNumber = pProductNumber;
}
public void setPrice(float pItemPrice) {
ItemPrice = pItemPrice;
}
public String getName() {
return ItemName;
}
public int getNumber() {
return ItemNumber;
}
public int getStock() {
return ItemsinStock;
}
public float getItemPrice() {
return ItemPrice;
}
public float getTotalValue() {
return ItemsinStock * ItemPrice;
}
public void setItemsinStock(int pItemsinStock) {
ItemsinStock = pItemsinStock;
}
[code=java]
public String toString() {
return "Item Number[" + ItemNumber + "] Name[" + ItemName
+ "] Quantity[" + ItemsinStock + "] Price Per Unit ["
+ ItemPrice + "] Line Item Value[$" + getTotalValue() + "]";
}
}
I am sorry I do not know how to add the code thingy to make it show up right.
package InventoryProgram;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
/**
*
* @author kyle
*/
public class ProductInventory2 {
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US);
ArrayList<Product> myItemInventory = new ArrayList<Product>();
System.out.println();
System.out.println();
System.out.println();
System.out.println("Welceome to Warehouse Inventory");
System.out.println();
System.out.println("Here is a list of Iventoried Items");
myItemInventory.add(new Product("Poles", 3,75.00f, 4));
myItemInventory.add(new Product("Transformers", 1,96.75f, 10));
myItemInventory.add(new Product("CutOuts", 2, 36.00f, 100));
myItemInventory.add(new Product("LED LIGHT", 4, 15.00f, 25));
Collections.sort(myItemInventory);
System.out.println();
System.out.println();
System.out.println("Product Information");
double totalInventoryValue = 0;
for (Product item : myItemInventory) {
System.out.println(item.toString());
totalInventoryValue = totalInventoryValue + item.getTotalValue();
}
System.out.println(currency.format(totalInventoryValue));
System.out.println();
System.out.println();
System.out.println("Exiting the Warehouse Inventory");
System.out.println();
System.out.println();
}
public double getTotalValue() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
class Product implements Comparable<Product> {
protected String ItemName;
protected int ItemNumber;
protected int ItemsinStock;
protected float ItemPrice;
double restockfee;
public Product(String ItemName, int ItemNumber, int ItemsinStock, float ItemPrice){
}
Product() {
setName("unknown");
setNumber(-1);
setPrice(0);
setItemsinStock(0);
}
Product(String pItemName, int pItemNumber, float pItemPrice,
int pItemsinStock) {
setName(pItemName);
setNumber(pItemNumber);
setPrice(pItemPrice);
setItemsinStock(pItemsinStock);
}
@Override
public int compareTo(Product pAnotherProduct) throws ClassCastException {
if (this.getNumber() > pAnotherProduct.getNumber())
return 1;
else
return -1;
}
public void setName(String pProductName) {
ItemName = pProductName;
}
public void setNumber(int pProductNumber) {
ItemNumber = pProductNumber;
}
public void setPrice(float pItemPrice) {
ItemPrice = pItemPrice;
}
public String getName() {
return ItemName;
}
public int getNumber() {
return ItemNumber;
}
public int getStock() {
return ItemsinStock;
}
public float getItemPrice() {
return ItemPrice;
}
public float getTotalValue() {
return ItemsinStock * ItemPrice;
}
public void setItemsinStock(int pItemsinStock) {
ItemsinStock = pItemsinStock;
}
[code=java]
public String toString() {
return "Item Number[" + ItemNumber + "] Name[" + ItemName
+ "] Quantity[" + ItemsinStock + "] Price Per Unit ["
+ ItemPrice + "] Line Item Value[$" + getTotalValue() + "]";
}
}
I am sorry I do not know how to add the code thingy to make it show up right.