Hi! I've been trying to get my inventory program to compile, but haven't had any luck. My instructor tells me that my arguments in the Inventory3 class need to match the datatype of the constructor in my Product class. I'm sure this is something rather simple that I should be able to figure out, but I'm at my wits end trying to make this work. Does anyone have any suggestions? My code is below. Thanks so much to anyone with advice in advance!!
Code:
class Product { private int itemNumber; //Number assigned to product private String itemName; //Name of product private int stock; //Number of units of the product in stock private double price; //Price of each unit of the product public Product () //constructor for the product class { itemNumber = 0; itemName = ""; stock = 0; price = 0.00; } //end constructor public Product (int itemNumber, String itemName, int stock, double price) //begin constructor for item array { this.itemNumber = itemNumber; this.itemName = itemName; this.stock = stock; this.price = price; } public void setItemNumber(int itemNumber) //sets and gets the item number { this.itemNumber = itemNumber; } public int getItemNumber() { return itemNumber; } public void setItemName(String itemName) //sets and gets the item name { this.itemName = itemName; } public String getItemName() { return itemName; } public void setStock(int stock) //sets and gets the number of units in stock { this.stock = stock; } public int getStock() { return stock; } public void setPrice(double price) //sets and gets the price per unit { this.price = price; } public double getPrice() { return price; } public double value() //calculates the value of the stock by multiplying the number of units on hand by the price of each unit { return stock * price; } public String toString() { return "Item Number: "+itemNumber + "\nProduct Name: "+itemName+"\nQuantity in Stock: "+stock+"\nPrice per Unit: $"+price+"\nValue of Entire Stock: $"+value(); } }//end class Product class Plastic extends Product { private String itemColor; //color of product public Plastic () //begin constructor { super(); itemColor = ""; } public Plastic ( int itemNumber, String itemName, int stock, double price, String itemColor ) { super(itemNumber, itemName, stock, price ); this.itemColor = itemColor; //add new attribute } public void setItemColor(String itemColor) //sets and gets the item color { this.itemColor = itemColor; } public String getItemColor() { return itemColor; } public double restockFee() { return value() * 0.05; } } //end class Plastic public class Inventory3 //begin class Inventory3 { public static void main( String args[]) { Product[] item = new Product [4]; Product item1 = new Product (1003182, "Polytrope TPP", 7, 1.81, "Black" ); Product item2 = new Product (1003296, "Polyvin PVC", 3, 1.72, "Light Neutral" ); Product item3 = new Product (1013972, "Polyvin PVC-DC", 8, 1.75, "Beige" ); Product item4 = new Product (1019392, "Invision", 9, 1.57, "Medium Dark Pewter" ); item[0] = item1; item[1] = item2; item[2] = item3; item[3] = item4; double all = 0.00; for (int total= 0; total < 4;total++) { all = all + item[total].value(); } for (Product myProduct: item) { System.out.println(item); System.out.println(); } System.out.println("The Value of all items combined is: $"+all); } //end method main } //end class Inventory3
Comment