0

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();
}

}

DuckyPGRMR
  • 23
  • 3
  • 2
    The compiler error is pretty much on point: there is no static method `max(Circle, Circle)` in class `Circle`. – Turing85 Aug 08 '21 at 21:03
  • You don't post the code for the `max(...)` method or at least the method signature. Your question is not answerable without this, other than to say that your own method signature is wrong. – Hovercraft Full Of Eels Aug 08 '21 at 21:03
  • Class `Circle` doesn't have method `max(Circle, Circle)`. If `Rectangle.max(rectangle1,rectangle2))` is working for you, try to implement it in the same way – Frido Aug 08 '21 at 22:35

0 Answers0