I am not getting error messages, but it is not doing what I ant it to do..here is the assignment:
Modify the Inventory Program by creating a subclass of the product class that uses one
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.
package javaapplication27;
public class FGInventory2{
}
class Product implements Comparable
{
private long itemNumber; // class variable that stores the item number
private String itemName; // class variable that stores the item name
private long invQuantity; // class variable that stores the quantity in stock
private double itemPrice; // class variable that stores the item price
public Product(long number, String name, long quantity, double price) // Constructor for the Supplies class
{
itemNumber = number;
itemName = name;
invQuantity = quantity;
itemPrice = price;
}
public void setItemNumber(long number) // Method to set the item number
{
this.itemNumber = number;
}
public long getItemNumber() // Method to get the item number
{
return itemNumber;
}
public void setItemName(String name) // Method to set the item name
{
this.itemName = name;
}
public String getItemName() // Method to get the item name
{
return itemName;
}
public void setinvQuantity(long quantity) // Method to set the quantity in stock
{
invQuantity = quantity;
}
public long getInvQuantity() // Method to get the quantity in stock
{
return invQuantity;
}
public void setItemPrice(double price) // Method to set the item price
{
this.itemPrice = price;
}
public double getItemPrice() // Method to get the item price
{
return itemPrice;
}
public double calculateInventoryValue() // Method to calculate the value of the inventory
{
return itemPrice * invQuantity;
}
public int compareTo(Object o)
{
Product p = null;
try
{
p = (Product) o;
}
catch (ClassCastException cE)
{
cE.printStackTrace();
}
return itemName.compareTo(p.getItemName());
}
public String toString()
{
return "Item #: " + itemNumber + "\nName: " + itemName + "\nQuantity: " + invQuantity + "\nPrice: $" + itemPrice + "\nValue: $" + calculateInventoryValue();
}
} //end class Product
public class FGInventory2
{
Product[] supplies;
public static void main(String[] args)
{
Inventory inventory = new Inventory();
inventory.addProduct(new Product(685, "How to Losse a Guy in 10 days", 4, 19.99));
inventory.addProduct(new Product(565, "Cyote Ugly", 8, 19.98));
inventory.addProduct(new Product(785, "Legally Blonde", 10, 19.99));
inventory.addProduct(new Product(578, "Sweet Home Alabama", 8, 18.56));
System.out.println(); // blank line
System.out.println("Welcome to DVD Inventory 1.0"); //display header
inventory.sortByName(); //sort list by name
System.out.println(); // blank line
inventory.showInventory(); //display inventory
double total = inventory.calculateTotalInventory();
System.out.println("Total Value is: $" + total);
}
public void sortByName()
{
for (int i = 1; i < supplies.length; i++)
{
int j;
Product val = supplies[i];
for (j = i - 1; j > -1; j--)
{
Product temp = supplies[j];
if (temp.compareTo(val) <= 0)
{
break;
}
supplies[j + 1] = temp;
}
supplies[j + 1] = val;
}
}
public String toString() //creates a String representation of the array of products
{
String s = "";
for (Product p : supplies)
{
s = s + p.toString();
s = s + "\n\n";
}
return s;
}
public void addProduct(Product p1) //Increases the size of the array
{
if (supplies == null)
{
supplies = new Product[0];
}
Product[] p = supplies; //Copy all products into p first
Product[] temp = new Product[p.length + 1]; //create bigger array
for (int i = 0; i < p.length; i++)
{
temp[i] = p[i];
}
temp[(temp.length - 1)] = p1; //add the new product at the last position
supplies = temp;
}
public double calculateTotalInventory() //sorting the array using Bubble Sort
{
double total = 0.0;
for (int i = 0; i < supplies.length; i++)
{
total = total + supplies[i].calculateInventoryValue();
}
return total;
}
public void showInventory()
{
System.out.println(toString()); //call our toString method
}
} //end Class FGInventory2