Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 1 Abstract Class You have been provided the abstract class GeometricThing.

ID: 3817993 • Letter: P

Question

Part 1 Abstract Class

You have been provided the abstract class GeometricThing. Create the concrete class Square, according to the UML, below. You may use TestGeometricThing.java to run the Square class. GeometricThing.java and TestGeometricThings.java have been provided.

/* Create a class Square that is a child of the abstract class GeometricThing.

Square

- side : double //default value of 1.0

+Square() //sets side to default of 1.0 +Square(side : double) //sets property side to parameter side.

+getSide() : double //returns the property side.

+toString() : String //returns a string that describes the side value. */

Part 2 Add to TestGeometricThing.java. Declare and ArrayList of GeometricThing. Add geoThing1, geoThing2, and geoThing3 to the ArrayList. Create a method public static double sumArea(ArrayList list)that will return the summed area of every object in list.

Part 3 Add three more objects to the ArrayList. These can be any of the children of GeometricThing. Create a method public static GeometricThing findBiggestThing(ArrayList list) that will return the largest GeometricThing in terms of area. Display the area of the returned object.

Output should look like this:

The two objects have the same area? false

Circle
The area is 78.53981633974483
The perimeter is 31.41592653589793

Rectangle
The area is 15.0
The perimeter is 16.0

Square
The area is 25.0
The perimeter is 25.0

Do circle and rectangle have same area? false
Total area in the ArrayList is 118.53981633974483
The largest area is 78.53981633974483

Square.java

TestGeometricThing.Java

GeometricThing.java

Circle.Java

public class Circle extends GeometricThing {

Rectangle.java

public class Rectangle extends GeometricThing {

Explanation / Answer

import java.util.ArrayList;
open class TestGeometricThing {
/** Main technique */
open static void main(String[] args) {
/Declare and instate two geometric articles
GeometricThing geoThing1 = new Circle(5);
GeometricThing geoThing2 = new Rectangle(5, 3);
GeometricThing geoThing3 = new Square(5);
System.out.println("The two items have a similar territory? " +
equalArea(geoThing1, geoThing2));
/Display circle
System.out.println("Circle");
displayGeometricThing(geoThing1);
/Display rectangle
System.out.println("Rectangle");
displayGeometricThing(geoThing2);
/Display square
System.out.println("Square");
displayGeometricThing(geoThing3);
System.out.println("Do circle and rectangle have same region? " +
equalArea(geoThing1, geoThing3));
}
/** A strategy for looking at the ranges of two geometric articles */
open static boolean equalArea(GeometricThing object1,GeometricThing object2) {
return object1.getArea() == object2.getArea();
}
/** A technique for showing a geometric question */
open static void displayGeometricThing(GeometricThing object) {
System.out.println("The range is " + object.getArea());
System.out.println("The edge is " + object.getPerimeter());
System.out.println();
}
}
GeometricThing.java
open dynamic class GeometricThing {
private String shading = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric question */
secured GeometricThing() {
dateCreated = new java.util.Date();
}
/** Construct a geometric protest with shading and filled esteem */
secured GeometricThing(String shading, boolean filled) {
dateCreated = new java.util.Date();
this.color = shading;
this.filled = filled;
}
/** Return shading */
open String getColor() {
return shading;
}
/** Set another shading */
open void setColor(String shading) {
this.color = shading;
}
/** Return filled. Since filled is boolean,
* the get strategy is named isFilled */
open boolean isFilled() {
return filled;
}
/** Set another filled */
open void setFilled(boolean filled) {
this.filled = filled;
}
/** Get dateCreated */
open java.util.Date getDateCreated() {
return dateCreated;
}
@Override
open String toString() {
return "made on " + dateCreated + " color: " + shading +
" and filled: " + filled;
}
/** Abstract strategy getArea */
open conceptual twofold getArea();
/** Abstract strategy getPerimeter */
open conceptual twofold getPerimeter();
}
Circle.Java
open class Circle augments GeometricThing {
private twofold range;
open Circle() {
}
open Circle(double range) {
super("red", false);
this.radius = range;
}
/** Return range */
open twofold getRadius() {
return range;
}
/** Set another range */
open void setRadius(double range) {
this.radius = range;
}
@Override/** Return zone */
open twofold getArea() {
return range * span * Math.PI;
}
/** Return measurement */
open twofold getDiameter() {
return 2 * range;
}
@Override/** Return border */
open twofold getPerimeter() {
return 2 * range * Math.PI;
}
/* Print the circle information */
open void printCircle() {
System.out.println("The circle is made " + getDateCreated() +
" and the sweep is " + range);
}
}
Rectangle.java
open class Rectangle amplifies GeometricThing {
private twofold width;
private twofold tallness;
open Rectangle() {
}
open Rectangle(double width, twofold tallness) {
this.width = width;
this.height = tallness;
}
/** Return width */
open twofold getWidth() {
return width;
}
/** Set another width */
open void setWidth(double width) {
this.width = width;
}
/** Return tallness */
open twofold getHeight() {
return tallness;
}
/** Set another tallness */
open void setHeight(double tallness) {
this.height = tallness;
}
@Override/** Return zone */
open twofold getArea() {
return width * tallness;
}
@Override/** Return border */
open twofold getPerimeter() {
return 2 * (width + tallness);
}
}