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: 3818117 • 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

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package geometricthing;

/**
*
* @author Lenovo
*/
import java.util.ArrayList;

public class TestGeometricThing {
/** Main method */
public static void main(String[] args) {
// Declare and initialize two geometric objects
GeometricThing geoThing1 = new Circle(5);
GeometricThing geoThing2 = new Rectangle(5, 3);
GeometricThing geoThing3 = new Square(5);
ArrayList<GeometricThing> list = new ArrayList<GeometricThing>();
list.add(geoThing1);
list.add(geoThing2);
list.add(geoThing3);
System.out.println("The two objects have the same area? " +
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 area? " +
equalArea(geoThing1, geoThing3));
System.out.println("Total area in the ArrayList is "+
sumArea(list));
System.out.println("The largest area is "+
findBiggestThing(list).getArea());

}

/** A method for comparing the areas of two geometric objects */
public static boolean equalArea(GeometricThing object1,GeometricThing object2) {
return object1.getArea() == object2.getArea();
}

/** A method for displaying a geometric object */
public static void displayGeometricThing(GeometricThing object) {

System.out.println("The area is " + object.getArea());
System.out.println("The perimeter is " + object.getPerimeter());
System.out.println();

}
public static double sumArea(ArrayList list){
double sum = 0.0;
Object[] list1 = list.toArray();
GeometricThing one;
for(Object obj : list1){
obj;
sum += one.getArea();
}
return sum;
}
public static GeometricThing findBiggestThing(ArrayList list){
double largest = 0.0;
int counter = 0;
Object[] list1 = list.toArray();
GeometricThing> GeometricThing large = null;
for(Object obj : list1){
obj;
if(counter == 0){
largest = one.getArea();
large = one;
}
if(one.getArea() > largest){
largest = one.getArea();
large = one;
}
counter++;
}
return large;
}
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package geometricthing;

public class Square extends GeometricThing {
private double side;

public Square() {
this.side = 1.0;
}

public Square(double side) {
this.side = side;
}

/** Return width */
public double getSide() {
return this.side;
}
public String toString(){
return "Square";
}
@Override /** Return area */
public double getArea() {
return this.side * this.side;
}
@Override /** Return perimeter */
public double getPerimeter() {
return 4 * this.side;
}
}