I’m working on an exercise for my course and I’ve stumbled upon a problem through the coding. I’m supposed to make an extended class and I think the problem I’m having is the parameter I’m giving for the constructor.
Here is the direct superclass:
public class ElectricalComponent extends Component
{
private int myMinRating,
myMaxRating;
public ElectricalComponent( String partNumber, int versionNumber, int minRating, int maxRating )
{
super( "Electrical", partNumber, versionNumber );
myMinRating = minRating;
myMaxRating = maxRating;
}
public int getMinRating() { return myMinRating; }
public int getMaxRating() { return myMaxRating; }
}
And here is the class I’m working on:
public class HighvoltageComponent extends ElectricalComponent
{
private int myMinRating, myMaxRating;
public HighvoltageComponent( String partNumber, int versionNumber)
{
super( "Electrical", partNumber, versionNumber );
myMinRating = 50000;
myMaxRating = 200000;
}
}
My problem is in the subclass where it says : "HighvoltageComponent ( String … ) "
When I run the main class which is
public static void main( String[] args )
{
// test your code here
Component a = new HighvoltageComponent( "HV12", 0 );
System.out.println( a.toString() );
System.out.println( a.getTypeName() );
System.out.println( a.getPartNumber() );
System.out.println( a.getVersionNumber() );
}
I get the error that says
"HighvoltageComponent.java:9: cannot find symbol
symbol : constructor ElectricalComponent(java.lang.String,java.lang.String,int) "
Why is this happening?
Also, could you please tell me if I’m doing this question the right way? This is the question:
A HighvoltageComponent is an ElectricalComponent with a minimum rating of 50000 and a maximum rating of 200000. Complete the following definition of HighvoltageComponent. (You will need to insert code at more than one place in the code area below.)
Thanks, Rohan
ElectricalComponentconstructor requires four parameters, you passed only three params in callsuper( "Electrical", partNumber, versionNumber );inHighvoltageComponentclassYou super call should be something like this