my assignment (in summary) is to override the following methods, in my code: compareTo (interface Comparable), toString (class GeometricObject) and equals (class Object).
I am new to Java and am not sure if I am using the @override methods correctly. I would appreciate any feedback, and if you could point me to the right direction.
Partial code that I'm using to override the methods stated:
Circle.java partial code
//Circle.java
@Override /**Override equals(class Object**/
public boolean equals(Object o) {
return this.compareTo((Circle)o) == 0;
}
@Override /**Override compareTo(interface Comparable)**/
public int compareTo(Circle o) {
if (this.radius > o.radius)
return 1;
else if (this.radius < o.radius)
return -1;
else
return 0;
}
@Override /**Override toString(class GeometricObject**/
public String toString(GeometricObject o) {
return super.toString()+"\nDate created:"+getDateCreated()+"\nRadius:"+radius; }
GeometricObject.java partial code
//GeometricObject.java
/** Return color */
public String getColor() {
return color;
}
/** Set a new color */
public void setColor(String color) {
this.color = color;
}
/** Return filled. Since filled is boolean,
* the get method is named isFilled */
public boolean isFilled() {
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled) {
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated() {
return dateCreated;
}
@Override
public String toString() {
return "created on"+dateCreated+"\ncolor:"+color+" and filled:" + filled;
}
/** Abstract method getArea */
public abstract double getArea();
/** Abstract method getPerimeter */
public abstract double getPerimeter();
}