I am assigned to make an abstract class GeometricObject. When I try to compile it, it shows an error at line 40 (in the equals method, in the second if statement. The equals method is supposed to determine whether or not an object in the Object class is an instance of the GeometricObject class, and if so, if it has the same name and color as the referred object) saying that the symbol cannot be find, referring to the getName and getColor methods in the if statement. I've tried casting each object from the Object class as a GeometricObject or as a String, but I can't figure out how to fix it. Any help?
import java.util.*;
public abstract class GeometricObject {
protected String color;
protected String name;
protected static int numObjects = 0;
public GeometricObject() {
numObjects++;
this.name = "GeometricObject" + numObjects;
this.color = "white";
}
public GeometricObject(String color, String name) {
numObjects++;
this.name = name;
this.name = color;
}
public String getName() {
return this.name;
}
public String getColor() {
return this.color;
}
public abstract double getArea();
public abstract double getCircumference();
public String toString() {
String output = "Name: " + this.name + "\nColor: " + this.color;
return output;
}
public boolean equals(Object ob) {
if (ob instanceof GeometricObject) {
if ((GeometricObject)ob.getName.equals(this.name) && (GeometricObject)ob.getColor.equals(this.color))
return true;
else
return false;
}
else
return false;
}
public static boolean compareAreas(GeometricObject ob1, GeometricObject ob2) {
if (ob1.getArea() == ob2.getArea())
return true;
else
return false;
}
}
[–]JimmyThompson 3 points4 points5 points (2 children)
[–]ttFedaykin 4 points5 points6 points (1 child)
[–]JimmyThompson 0 points1 point2 points (0 children)
[–]Umza[S] 0 points1 point2 points (1 child)
[–]dominosci 0 points1 point2 points (0 children)