Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

/* Create a class Square that is a child of the abstract class GeometricObect. 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. */ 

TestGeometricThing.Java

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); 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)); } /** 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(); } } 

GeometricThing.java

public abstract class GeometricThing { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricThing() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricThing(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } /** 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, * the 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; } @Override public String toString() { return "created on " + dateCreated + " color: " + color + " and filled: " + filled; } /** Abstract method getArea */ public abstract double getArea(); /** Abstract method getPerimeter */ public abstract double getPerimeter(); } 

Circle.Java

public class Circle extends GeometricThing {

 private double radius; public Circle() { } public Circle(double radius) { super("red", false); this.radius = radius; } /** Return radius */ public double getRadius() { return radius; } /** Set a new radius */ public void setRadius(double radius) { this.radius = radius; } @Override /** Return area */ public double getArea() { return radius * radius * Math.PI; } /** Return diameter */ public double getDiameter() { return 2 * radius; } @Override /** Return perimeter */ public double getPerimeter() { return 2 * radius * Math.PI; } /* Print the circle info */ public void printCircle() { System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius); } } 

Rectangle.java

public class Rectangle extends GeometricThing {

 private double width; private double height; public Rectangle() { } public Rectangle(double width, double height) { this.width = width; this.height = height; } /** Return width */ public double getWidth() { return width; } /** Set a new width */ public void setWidth(double width) { this.width = width; } /** Return height */ public double getHeight() { return height; } /** Set a new height */ public void setHeight(double height) { this.height = height; } @Override /** Return area */ public double getArea() { return width * height; } @Override /** Return perimeter */ public double getPerimeter() { return 2 * (width + height); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

define EFFECTIVE PARTICIPATION

Answered: 1 week ago