I’m trying to create a new object using the parameters passed in, then use that new object to place in the setCarColor method listed below. But my setCarColor in my constructor is giving an error for my clv variable. It says “Can not find symbol”. The clv is my variable from the CarColor class. I’m not sure if it is because the parameters being passed in(rdIn, grnIn, bluIn)are integers or what? Does anyone have any ideas please?
Best Regards,
public abstract class Vehicle
{
private String shapeId;
CarColor carColor;//CarColor data member from the ColorValue.java class
public Shape(String bodyid, int rd, int grn, int ble)
{
CarColor clv = new CarColor(rdIn, grnIn, bluIn);
setCarColor(clv(rd, grn, ble));// <---error here
}
private CarColor getCarColor()
{
return carColor;
}
private void setCarColor(int redIn, int blueIn, int greenIn)
{
if (redIn == 0 || blueIn == 0 || greenIn == 0 )
{
System.out.println("The value entered in is null. Please try again ");
System.exit(-1);
}
}
This line is nearly fine:
… although it doesn’t populate the
colorValuefield, which is what you might have been expecting, and you don’t actually haverdIn,grnInandbluInvariables. Did you meanrd,grn,ble? (It helps if you don’t contract names like this, by the way.)But this line is broken in two ways:
Firstly, it’s trying to call a method called
clv. You don’t have such a method. You’ve got a variable calledclv, but you don’t “call” a variable.The second problem is that if you really meant this:
then you’d be using incorrect arguments –
setColorValuedoesn’t have one parameter of typeColorValue, it has three parameters, allints.Unfortunately it’s not clear what you’re attempting to do, so it’s hard to advise you. Perhaps you mean this: