import java.text.DecimalFormat;
public class Inventory {
int inventorySize = 30;
private Product items[] = new Product [inventorySize];
DecimalFormat formatter = new DecimalFormat ("$##,###.00");
// Adds a product to the array of products.
public void addProduct(Product item) {
for (int i =0; i < inventorySize; i++) {
if (items[i] == null) {
items[i] = item;
return;
}
}
}
public double getTotalInvValue() {
double sumOfInventory = 0.0;
for (Product item : items) {
if (item != null) {
sumOfInventory += item.getItemValue();
}
}
return sumOfInventory;
}
public void printInventory() {
System.out.println("Printing items in inventory...\n");
boolean hasItems = false;
for (Product item : items) {
if(item !=null) {
hasItems = true;
System.out.println(item.toString() + "Quantity:" + item.getQuantityOnHand() + "Value of Stock: " + formatter.format(item.getItemValue()));
}
}
// If no items were found, print a message saying the inventory is empty
if (!hasItems) {System.out.println("Inventory is empty at the moment. \n"); }
}
}
public class Product{
//Private variables
private String name;
private int quantity;
private double price;
private int productid = 0;
public Product() {
this(0,"American Gangster",4,19.99);
}
public Product(int productID, String itemname, int quantityOnHand,double itemprice) {
productid = productId;
setName(itemname);
setQuantityOnHand(quantityOnHand);
setPrice(itemprice);
}
public void setName(String itemname) {
name = itemname;
}
public void setPrice(double itemPrice) {
if (itemPrice > 0.00) {
price =itemPrice;
}
else { price = 0.00;}
}
public String getName() {
return name;
}
public int getQuantityOnHand() {
return quantity;
}
public double getPrice() {
return price;
}
public double getItemValue() {
return (price * (double)quantity);
}
public String toString() {
return name + "-" + price;
}
}
// Inherited class DVD from the base class Product
public class DVD {
// Holds the year of movie
private int movieyear;
public DVD(int productId, String itemname, int quantityOnHand, double itemprice, int year) {
super(productId, itemname,quantityOnHand, itemprice);
movieyear = year;
}
public void setYear(int year) {
movieyear = year;
}
//Get the year of this DVD
public int getYear() {
return movieyear;
}
// adding a 5% restocking fee
public double getItemValue() {
return super.getItemValue() *1.05;
}
public double getRestockinkingFee() {
return super.getItemValue() * .05;
}
}
here is a list of the error that I have.
.\Product.java:13: cannot find symbol
symbol :variable productId
location class Product
productid=productId;
^
Product.java:15: cannot find symbol
symbol : method setQuantityOnHand(int)
location: class Product
setQuantityOnHand(quantityOnHand);
^
DVD.java:8:Object() in java.lang.Object cannot be applied to (int.java.lang.String,int,double)
super(productId,itemname,quantityOnHand,itemprice);
DVD.java:23: cannot find symbol
symbol : method getItemValue()
location: class java.lang.Object
return super.getItemValue() * 1.05;
^
DVD.java:27: cannot find symbol
symbol : method getItemValue()
location :class java.lang.Object
return super.getItemValue() * .05;
^

New Topic/Question
Reply




MultiQuote






|