public class Main {
public static void main(String[] args) {
System.out.println("Computer Parts Inventory:");
Restock[] parts = new Restock[5];//Create array
Restock[0]= new Restock(1,"HDD",12,35,420,"Seagate",441);//Create classes
Restock[1]= new Restock(2,"Mobo",5,40,200,"ASUS",210);
Restock[2]= new Restock(3,"CPU",3,50,150,"Intel",157.50);
Restock[3]= new Restock(4,"GPU",6,75,450,"ATI",472.50);
Restock[4]= new Restock(5,"PSU",4,15,60,"Thermalake",63);
for (int x =0; x<=5; x++ ){ //Advanced for loop to init all classes
System.out.println();
System.out.println("Label product as " +parts[x].getName());
System.out.println("Mark price as $"+parts[x].getprice());
System.out.println("Total units "+parts[x].getunits());
System.out.println("Total worth is $"+parts[x].value());
System.out.println("Vendor make:"+parts[x].getMFG);
System.out.println("Restock value:"+parts[x].getrestockfee);
}//end for
}//End Main
}//End program
Storage Class:
public class storage{
public String label;
public int product;
public int units;
public double price;
public double value;
//Constructor for unknowns
public storage()
{
label = "";
product = 0;
units = 0;
price = 0;
value = 0;
}
//Constructor with peramiters
public storage(int product, String label, int units, double price, double value)
{
this.label = label;
this.price = price;
this.product = product;
this.units = units;
this.value = value;
}
//set and store values
public void setName(String name)
{
this.label = name;
}
String getName()
{
return label;
}
public void setprice(double price)
{
this.price = price;
}
public double getprice()
{
return price;
}
public void setproduct(int product)
{
this.product = product;
}
public double getproduct()
{
return product;
}
public void setunits(int units)
{
this.units = units;
}
public double getunits()
{
return units;
}
public double value()
{
return price * units;
}
}
Subclass of storage class:
public class Restock extends storage{
// Declare varibles
String MFG;
double restockfee;
//construct varibles for unknowns
public Restock(){
MFG="";
restockfee=0;
}
//Constructor
public Restock(int product, String label, int units, double price, double value, String MFG, double restockfee){
this.MFG = MFG;
this.restockfee = restockfee;
}
//construct get and set
public void setMFG(String MFG){
this.MFG = MFG;
}
String getMFG(){
return MFG;
}
//call value method
public double getValue()
{
//add restock fee
return ((getunits() * getprice()) * 1.05);
}//end method
} //end class
Restock array in Main class does not reference to the Restock class resulting in cannot find symbol error.
System.out.println("Vendor make:"+parts[x].getMFG);
System.out.println("Restock value:"+parts[x].getrestockfee);
These lines also produce the cannot find symbol error @ getMFG and getrestockfee. This program worked prior to adding the subclass. Not sure what I did to break it...
Compiler error data:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: variable Restock
location: class inventory.Main
at inventory.Main.main(Main.java:17)
Java Result: 1

New Topic/Question
Reply



MultiQuote



|