I am having trouble figuring out my code and was hoping someone could point me in the right direction. Below is my code what I need to due is create a method to add and display the value of the entire inventory. I have what I think is the correct code but it's not working. Help is greatly appreciated
class Inventory3
{
public static final int MAXIMUM_ITEMS = 4;
private static Product product[] = new Product[MAXIMUM_ITEMS];
public static void main(String args[])
{
buildInventory();
getInventory();
}
// Build the inventory, storing 10 different products.
public static void buildInventory()
{
product[0] = new Product(1001, "Megaforce", 10, 18.95);
product[1] = new Product(502, "Abyss", 25, 12.95);
product[2] = new Product(1003, "Deep Impact", 65, 21.95);
product[3] = new Product(750, "Forest Gump", 28, 7.95);
Arrays.sort(product);
}
public static void getInventory()
{
System.out.println(); // blank line
System.out.println("Welcome to DVD Inventory 1.0"); //display header
System.out.println();
for(int i = 0; i < product.length; i++)
{
System.out.println("Item Number: " + product[i].getItemNumber());
System.out.println("Item Name: " + product[i].getItemName());
System.out.println("Inventory On Hand: " + product[i].getInvQuantity());
System.out.println("Item Price: $" + product[i].getItemPrice());
System.out.println("Value of Inventory: $" + product[i].getValue());
System.out.println("Restock Fee: $" + (product[i].getValue()) * 0.05);
System.out.println();
}
}
public double entireValue()
{
double value = 0;
for (int i = 0; i < Product; i++)
{
value = value + product[i].getValue();
}
return value;
}
public void display()
{
System.out.printf("Total Value is: $%.2f\n\n", entireValue());
}
} //end Class Inventory3
Below is the error I get when I try to complie this into my code
Inventory3.java:104: cannot find symbol
symbol : variable Product
location: class Inventory3
for (int i = 0; i < Product; i++)
^
1 error
here is my complete working code so far
import java.util.Arrays;
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 long getItemNumber() { return itemNumber; } // Method to set item number
public String getItemName() { return itemName;} // Method to set the item name
public long getInvQuantity() { return invQuantity;} // Method to set the quantity in stock
public double getItemPrice() { return itemPrice;} // Method to get the item Price
public double getValue() { return (double) invQuantity * itemPrice; } // Method to calculate the valure of the inventory
public int compareTo(Object o)
{
Product p = null;
try
{
p = (Product) o;
}
catch (ClassCastException cE)
{
cE.printStackTrace();
}
return itemName.compareTo(p.getItemName());
}
} //end class Product
class DVD extends Product
{
public DVD(int itemNumber, String itemName, long invQuantity, double itemPrice)
{
super(itemNumber, itemName, invQuantity, itemPrice);
}
public double getValue()
{
double inventoryValue = super.getValue();
return (inventoryValue * 1.05);
}
}
class Inventory3
{
public static final int MAXIMUM_ITEMS = 4;
private static Product product[] = new Product[MAXIMUM_ITEMS];
public static void main(String args[])
{
buildInventory();
getInventory();
}
// Build the inventory, storing 10 different products.
public static void buildInventory()
{
product[0] = new Product(1001, "Megaforce", 10, 18.95);
product[1] = new Product(502, "Abyss", 25, 12.95);
product[2] = new Product(1003, "Deep Impact", 65, 21.95);
product[3] = new Product(750, "Forest Gump", 28, 7.95);
Arrays.sort(product);
}
public static void getInventory()
{
System.out.println(); // blank line
System.out.println("Welcome to DVD Inventory 1.0"); //display header
System.out.println();
for(int i = 0; i < product.length; i++)
{
System.out.println("Item Number: " + product[i].getItemNumber());
System.out.println("Item Name: " + product[i].getItemName());
System.out.println("Inventory On Hand: " + product[i].getInvQuantity());
System.out.println("Item Price: $" + product[i].getItemPrice());
System.out.println("Value of Inventory: $" + product[i].getValue());
System.out.println("Restock Fee: $" + (product[i].getValue()) * 0.05);
System.out.println();
}
}
} //end Class Inventory3