Question
package tasks; class GeometricObject { private String color = white; private boolean filled; private java.util.Date dateCreated; private String name = noname; /** Construct a default
package tasks;
class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; private String name = "noname"; /** Construct a default geometric object */ public GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with the specified color * and filled value */ public GeometricObject(String color, boolean filled, String name) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; this.name = name; } /** Return color */ public String getColor() { return color; } /** Set a new color */ public void setColor(String color) { this.color = color; } /** Return filled. Since filled is boolean, its get method is named isFilled */ public boolean isFilled() { return filled; } /** Set a new filled */ public void setFilled(boolean filled) { this.filled = filled; } /** Get dateCreated */ public java.util.Date getDateCreated() { return dateCreated; } /** Return name */ public String getName() { return name; } /** Set a new name */ public void setName(String name) { this.name = name; } /** Return a string representation of this object */ public String toString() { return "created on " + dateCreated + " color: " + color + " and filled: " + filled; } } class Circle //Create a Circle class { double radius; public Circle() { radius=1.0; } } class Rectangle //Creates a Rectangle class { double width; double height; public Rectangle() { width=1.0; height=1.0; } } public class Triangle extends GeometricObject //Creates Triangle class That Extends Geometric object { double side1=1.0; double side2=1.0; double side3=1.0; double permiter; double area,value; public Triangle() { } public Triangle(double side1,double side2,double side3) { this.side1=side1; this.side2=side2; this.side3=side3; } public double getPerimeter() { permiter=(side1+side2+side3); return permiter; } public double getArea() { value= permiter*((permiter-side1)*(permiter-side2)*(permiter-side3)); area=Math.sqrt(value); return area; } /** Return a string representation of this object */ public String toString() { return "created For Finding Perimeter " + permiter + " And Area: "+ area; } public static void main(String[] args) { Circle obj=new Circle(); Rectangle obj2=new Rectangle(); Triangle obj3=new Triangle(2.0,3.0,4.0); System.out.println("The Permeter of a Triangle is:"+obj3.getPerimeter()); System.out.println("The Area of Triangle is:"+obj3.getArea()); System.out.println(obj3.toString()); } }
Based on the code above. Modify the GeometricObject class to implement the Comparable interface, and define a static max method in the GeometricObject class for finding the larger of two GeometricObject objects.
Write a test program that uses the max() method to find the larger of two circles and the larger of two rectangles. Use the appropriate methods to determine if two GeometricObjects are the same.
Add all your objects to an ArrayList, sort it, then print out the sorted ArrayList.
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