how can I call a true or false value created with my "public boolean equals method" in a later method "public static void main(String[] args)"?
public Car(String color, double insurance)
{
this.color = color;
this.insurance = insurance;
}
public boolean equals(Car other)
{
if (this.color.equals(other.color) && this.insurance.equals(other.insurance))
{
return true;
}
else
{
return false;
}
}
I get error: cannot invoke equals(double) on the primitive type double
equals(Car other)belongs toCarclass which means you can invoke them on Car instances likecarInstance.euqlas()(2) If you want to override already existingequalsmethod then you need to declare it usingequals(Object other)notequals(Car other).if (c1.equals(c2))-- but your equals method is broken. It should take an Object parameter, not a Car parameter.this.color.equals(other.color) && this.insurance.equals(other.insurance;, and you never even callequals. Also, writingif(true)is completely useless..equals(..)on adouble. The user should instead usethis.insurance == other.insurance@Overrideto catch the method signature mismatch.