import java.util.Date;
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
protected GeometricObject() {
dateCreated = new java.util.Date();
}
protected GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public Date getDateCreated() {
return dateCreated;
}
@Override
public String toString() {
return "created on " + dateCreated + "\ncolor:" + color + " and filled:" + filled;
}
public abstract double getArea();
public abstract double getPerimeter();
}
```java
public class Circle extends GeometricObject {
private double radius=1.0;
public Circle() {
super();
}
public Circle(double radius) {
super();
this.radius = radius;
}
public Circle(String color, boolean filled, double radius) {
super(color, filled);
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
@Override
public double getArea() {
return Math.PI * radius * radius;
}
@Override
public double getPerimeter() {
return 2 * Math.PI * radius;
}
}
```java
public class Rectangle extends GeometricObject {
private double width = 1.0;
private double higth = 1.0;
public Rectangle() {
super();
}
public Rectangle(double width, double higth) {
super();
this.width = width;
this.higth = higth;
}
public Rectangle(String color, boolean filled, double width, double higth) {
super(color, filled);
this.width = width;
this.higth = higth;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHigth() {
return higth;
}
public void setHigth(double higth) {
this.higth = higth;
}
@Override
public double getArea() {
return width * higth;
}
@Override
public double getPerimeter() {
return (width + higth) * 2;
}
}
```java
public class Test {
public static void main(String[] args) {
GeometricObject object1 = new Circle(5);
GeometricObject object2 = new Rectangle(5, 3);
System.out.println("The two objects have the same area ?" + equalArea(object1, object2));
display(object1);
display(object2);
System.out.println(object1.toString());
}
public static boolean equalArea(GeometricObject object1, GeometricObject object2) {
return object1.getArea() == object2.getArea();
}
public static void display(GeometricObject object) {
System.out.println();
System.out.println("The area is " + object.getArea());
System.out.println("Thhe perimeter is " + object.getPerimeter());
}
}
```java
"D:\java 12.0\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\lib\idea_rt.jar=60547:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\bin" -Dfile.encoding=UTF-8 -classpath D:\IDEA\untitled6\out\production\untitled6 Test
The two objects have the same area ?false
The area is 78.53981633974483
Thhe perimeter is 31.41592653589793
The area is 15.0
Thhe perimeter is 16.0
created on Sat Apr 11 20:31:06 CST 2020
color:white and filled:false
Process finished with exit code 0