I've been working on OOP with Java and cannot seem to figure out this error for the life of me. I call Circle in my Test and it keeps on outputting "The method max(Circle,Circle) is undefined for the type of Circle." I had a bunch of other silly bugs but resolved them after some time but this last one has been giving grave issues. The whole purpose of the max method is to compare two different geometric objects.
public class Comparable {
/** Main method */
public static void main(String[] args) {
// Create two Circle objects
Circle circle1 = new Circle(15, "red", true);
Circle circle2 = new Circle(10, "blue", false);
// Display circle1
System.out.println("\nCircle 1: " + circle1);
//print(circle1);
// Display circle2
System.out.println("\nCircle 2: " + circle2);
//print(circle2);
// Display larger circle
System.out.printf("\nThe larger of the two circles was " + Circle.max(circle1, circle2));
//printf(Circle.max(circle1, circle2));
// Create two Rectangle objects
Rectangle rectangle1 = new Rectangle(4, 5, "green", true);
Rectangle rectangle2 = new Rectangle(4.2, 5, "orange", true);
// Display circle1
System.out.println("\nRectangle 1: " + circle1);
//print(circle1);
// Display circle2
System.out.println("\nRectangle 2: " + circle2);
//print(circle2);
// Display larger circle
System.out.printf("\nThe larger of the two rectangles was " + Rectangle.max(rectangle1,rectangle2));
//printf(Rectangle.max(rectangle1, rectangle2));
}
// Displays a string
public static void print(String s) {
System.out.printf(s);
}
// Displays a GeometricObject
public static void print(GeometricObject o) {
System.out.printf(o);
}
}
public class Circle extends GeometricObject {
private double radius;
public Circle() {
}
public Circle(double radius) {
this.radius = radius;
}
public Circle(double radius,
String color, boolean filled) {
this.radius = radius;
setColor(color);
setFilled(filled);
}
/** Return radius */
public double getRadius() {
return radius;
}
/** Set a new radius */
public void setRadius(double radius) {
this.radius = radius;
}
@Override /** Return area */
public double getArea() {
return radius * radius * Math.PI;
}
/** Return diameter */
public double getDiameter() {
return 2 * radius;
}
@Override /** Return perimeter */
public double getPerimeter() {
return 2 * radius * Math.PI;
}
@Override /** Return String discription of Circle object */
public String toString() {
return super.toString() + "\nRadius: " + radius + "\nArea: " + getArea() +
"\nDiameter: " + getDiameter() + "\nPerimeter: " + getPerimeter();
}
}