Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have been provided the abstract class GeometricObject. Create the concrete class Square, according to the UML, below. Create a test program TestGeometricThing that will

You have been provided the abstract class GeometricObject. Create the concrete class Square, according to the UML, below.

Create a test program TestGeometricThing that will create two instances of Square and display information on the two objects. /* Create a class Square that is a child of the abstract class GeometricObject.

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 (25 points) Add to TestGeometricThing.java. Declare and ArrayList of GeometricObject. This ArrayList will be populated with objects that are children of GeometricObject (Rectangle, Circle, Triangle, and Square). You should have Rectangle.java and Circle.java from the textbook. We created Triangle.java in a previous homework. Add at 10 GeomtricObjects, i.e, Square, Circle, Rectangle, or Triangle 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 (25 points)

Create a method public static GeometricObject findBiggestThing(ArrayList list) that will return the largest GeometricObject in terms of area. Display the area of the returned object.

Part 4 ( 25 points) Add another method public static void displayObject(ArrayList list, int n)

that will display then information on the nth object of list. If n is not a valid index, the method should generate and throw and exception that the main can then process. You get to decide what exception (one built into Java or a custom exception) and how you would like to handle the exception (terminate the program, prompt for more input, etc).

public class Circle extends GeometricObject { private double radius; public Circle() { } public Circle(double radius) { 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); } }
public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(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(); }
public class Triangle extends GeometricObject { private double side1; private double side2; private double side3; public Triangle(){ side1 = 1; side2 = 1; side3 = 1; } public Triangle(double side1, double side2, double side3){ this.side1 = side1; this.side2 = side2; this.side3 = side3; } public void setSide1(double side1){ this.side1 = side1; } public void setSide2(double side2){ this.side2 = side2; } public void setSide3(double side3){ this.side3 = side3; } public double getSide1(){ return side1; } public double getSide2(){ return side2; } public double getSide3(){ return side3; } public double getArea(){ double s = (side1 + side2 + side3) / 2; double area = (Math.sqrt(s * (s-side1) * (s-side2) * (s - side3))); return area; } public double getPerimeter(){ return side1 + side2 + side3; } public String toString(){ return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3; } }
 public class Rectangle extends GeometricObject { 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_2

Step: 3

blur-text-image_3

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions