 | October 27, 2015

Assignment 5

(The Octagon class) Write a class named Octagon that extends GeometricObject and implements the Comparable andCloneableinterfaces. Assume that all eight sides of the octagon are of equal length. The area can be computed using following formula
Area = (2+4/√2) * side * side
Write a Test program that creates an Octagon object with side value 5 and displays its area and perimeter. Create a new object using clone method and compare the two objects using compareTo method.

Otagon
publicclass Octagon extendsGeometricObjectimplements Comparable, Cloneable {

privatedoubleside;

publicOctagon() {
}

public Octagon(doubleside) {
this.side = side;
}

//get method
publicdoublegetSide() {
returnside;
}

publicvoidsetSide(doubleside) {
this.side = side;
}

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

publicdoublegetPerimeter() {
returnside * 8;
}

public String toString() {
return”Area: ” + getArea() + “nPerimeter: ”
+ getPerimeter() + “nClone Compare: ” + “nFirst Compare: “;
}

publicintcompareTo(Octagon octagon) {
if(getArea() >octagon.getArea())
return 1;
elseif(getArea() 0)
System.out.print(“greater than first”);
else
System.out.print(“equal”);
}

//using clone method to compare
String cloneComparison = “Clone Compare: “;
older = oct;
Octagon clone = oct.clone();
if ( older.getArea() == clone.getArea() ){
cloneComparison = cloneComparison + “Equal”;
} else {
cloneComparison = cloneComparison + “Not Equal”;
}
//System.out.println(cloneComparison);
i++;
first = new Octagon(side);
System.out.println();
}
fin.close();
}
} Get a 5 % discount on an order above \$ 150
Use the following coupon code :
2020Discount

Category: Homework Help

Our Services:
Order a customized paper today!
Hello, we are here to help with your assignments