0

public class TestOctagon {
public static void main(String[] args) {
Octagon octagon = new Octagon(1);
System.out.println("1st Octagon " + octagon.toString());
System.out.println("The area is " + octagon.getArea());
System.out.println("The perimeter is " + octagon.getPerimeter());
Octagon octagon1 = new Octagon(2);
System.out.println("2nd Octagon " + octagon1.toString());
System.out.println("The area is " + octagon1.getArea());
System.out.println("The perimeter is " + octagon1.getPerimeter());
System.out.println(octagon == octagon1);
System.out.println(compareTo(octagon1)); //I'm trying to compare octagon to octagon1 but I keep getting an error message.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by vchandra
0

if you are using compareTo for two objects then that object should implement comparable interface. and compareTo will be used to compare two objects while you are using only one. it will be object1.compareTo(object2)
For example. String implements comparable interface.
String test = "hi";
String test1 = "HI";
System.out.println(test.compareTo(test1));

cheers !!!!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.