Question
package Project1; public class SimpleTriangleObject extends SimpleGeometricObject { private double base = 0; private double height= 0; private double side1 = 0; private double side2
package Project1;
public class SimpleTriangleObject extends SimpleGeometricObject {
private double base = 0;
private double height= 0;
private double side1 = 0;
private double side2 = 0;
public SimpleTriangleObject() {
}
public SimpleTriangleObject (
double base, double height, double side1, double side2) {
this.base = base;
this.height = height;
this.side1 = side1;
this.side2 = side2;
}
public SimpleTriangleObject(
double base, double height, double side1, double side2, String color, boolean filled) {
this.base = base;
this.height = height;
this.side1 = side1;
this.side2 = side2;
setColor(color);
setFilled(filled);
}
/** Return base */
public double getBase() {
return base;
}
/** Set a new base */
public void setBase(double base) {
this.base = base;
}
/** Return height */
public double getHeight() {
return height;
}
/** Set a new height */
public void setHeight(double height) {
this.height = height;
}
/** Return side1 */
public double getSide1() {
return side1;
}
/** Set a new side1 */
public void setSide1(double side1) {
this.side1 = side1;
}
/** Return side2 */
public double getSide2() {
return side2;
}
/** Set a new side1 */
public void setSide2(double side2) {
this.side2 = side2;
}
/** Return area */
public double getArea() {
return 0.5 * base * height;
}
/** Return perimeter */
public double getPerimeter() {
return side1 + side2 + base;
}
public String toString() {
return super.toString() +
" and the Base is " + getBase()
+ " and the Height is " + getHeight()
+ " and the Side1 is " + getSide1()
+ " and the Side2 is " + getSide2();
}
package Project1;
public class Project1 {
public static void main(String[] args) {
SimpleTriangleObject triangle =
new SimpleTriangleObject (4,5,5,6, "blue,", true);
System.out.println(triangle.toString());
System.out.println("Area: " + triangle.getArea());
System.out.println("Perimeter: " + triangle.getPerimeter());
System.out.println("Base: " + triangle.getBase());
System.out.println("Height: " + triangle.getHeight());
System.out.println("Side1: " + triangle.getSide1());
System.out.println("Side2: " + triangle.getSide1());
}
}
Please includes the following in the code above
From the project1, redo the triangle object to be compatable and colonable.
Implement the Cloneable and Comparable interfaces into the Project1's triangle object.
Submit only the new SimpleTriangleObject.java with above two interfaces implemented.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started