3 Replies - 543 Views - Last Post: 24 March 2012 - 05:03 PM Rate Topic: -----

#1 artillery  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 18-March 12

Cannot find symbol error to create new array element from a subclass

Posted 24 March 2012 - 03:06 PM

Main Class:
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

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot find symbol error to create new array element from a subclass

#2 artillery  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 18-March 12

Re: Cannot find symbol error to create new array element from a subclass

Posted 24 March 2012 - 03:27 PM

It may also be worth noting that there is an is overridden symbol at public class storage.
Was This Post Helpful? 0
  • +
  • -

#3 artillery  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 18-March 12

Re: Cannot find symbol error to create new array element from a subclass

Posted 24 March 2012 - 03:37 PM

Removed the errors from
System.out.println("Vendor make:"+parts[x].getMFG);
System.out.println("Restock value:"+parts[x].getrestockfee);
by removing the get from .getMFG and .getrestockfee
Was This Post Helpful? 0
  • +
  • -

#4 artillery  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 18-March 12

Re: Cannot find symbol error to create new array element from a subclass

Posted 24 March 2012 - 05:03 PM

So I figured this one out.
Restock[0]= new Restock(1,"HDD",12,35,420,"Seagate",441);//Create classes
Should be:
parts[0]= new Restock(1,"HDD",12,35,420,"Seagate",441);//Create classes
etc
etc
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1