0

I have a parent and child class being 'Toy' and 'Robot'. I would like to extend my Toy class to the Robot to simplify the constructors, methods from Toy, etc. When I run my Robot class VsCode tells me it cannot find the symbol of Toy pointing to the beginning of the code where I say to extend Toy. Not sure how to fix this problem and I can't figure out if it is a problem within my code or Visual Studio itself. Thank you

public class Toy {
    protected int productCode = 10000000;
    private String name;
    protected double MSRP;
    protected static final Random RNG = new Random();
    private String play;
    
    public Toy(String name, double msrp){
        this.name = name;
        this.MSRP = msrp;
        this.productCode = RNG.nextInt(productCode);
    }
    
    public String getPlay(){
        return this.play;
    }
    public void setPlay(String play){
        this.play = play;
    }
    public String getName(){
        return this.name;
    }
    public int getProductCode(){
        return this.productCode;
    }
    public double getMsrp(){
        return this.MSRP;
    }
    public void setName(String name){
        this.name = name;
    }
    public void setProductCode(int productCode){
        this.productCode = productCode;
    }
    public void setMrsp(int msrp){
        this.MSRP = msrp;
    }

    @Override
    public String toString(){
        return this.productCode + " " + this.name + ": " + this.MSRP;
    }

}
public class Robot extends Toy {
    public int charge;
    public String sound;
    public Robot(String sound){
        super("Robot",5.15);
        this.charge = 0; 
        this.sound = sound;
    }
    public int charged(){
        for(int i =0; i < 100; i++){
            this.charge += 1;
        }
        if(this.charge == 100){
            this.charge = 100;
        }
        return this.charge;
    }
}

This is the error I receive trying to run Robot.java

Robot.java:8: error: cannot find symbol
public class Robot extends Toy {
                           ^
  symbol: class Toy
1 error
Anewuser
  • 1
  • 1

0 Answers0