Question: Using the code below: // construct an Octagon // clone an Octagon // Write code to output area and perimeter, and compare Octagon objects o1

Using the code below:

// construct an Octagon

// clone an Octagon

// Write code to output area and perimeter, and compare Octagon objects o1 and o2.

public class Octagon {

private double side;

public Octagon() {

this.side = 1.0;

}

public Octagon(double side) {

this.side = side;

}

public double getArea() {

return (2 + 4 / Math.sqrt(2)) * side * side;

}

public double getPerimeter() {

return 8 * side;

}

public int compareTo(Object obj) {

if (this.getArea() > ((Octagon) obj).getArea()) {

return 1;

} else if (this.getArea() < ((Octagon) obj).getArea()) {

return -1;

} else {

return 0;

}

}

public boolean equals(Object obj) {

return this.side == ((Octagon) obj).side;

}

@Override

public Octagon clone() { //

try {

return (Octagon) super.clone();

} catch (CloneNotSupportedException ex) {

return null;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!