Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

] In the code provided here, you will find the class GeometricObject and Triangle (as you did in your first assignment). This question requests you

] In the code provided here, you will find the class GeometricObject and Triangle (as you did in your first assignment). This question requests you to do the following: A. Define a Circle class that extends GeometricObject and contains: Two double data fields named x and y that specify the center of the circle with get methods. A data field radius with a get method. A no-argument constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius. A constructor that creates a circle with the specified x, y, and radius. A method getArea() that returns the area of the circle. A method getPerimeter() that returns the perimeter of the circle. B. Define an EquilateralTriangle class that extends Triangle. The class contains: One double data field named side denotes the side of the triangle [an equilateral triangle is a special type of triangle where the sides are of the same length]. A constructor that creates an EquilateralTriangle with the specified side. Pass the value of the side to Triangles constructor: Triangle(double side1, double side2, double side3). In other words, you have to call super and pass side for all three arguments: side1, side2, and side3. C. Define a Rectangle class that extends GeometricObject. The class contains: Two double data fields named side1 and side2 denote the sides of the rectangle. A no-arg constructor that creates a default rectangle with 1 for each side. A constructor that creates a rectangle with the specified side1 and side2. A method getArea() that returns the area of the rectangle. A method getPerimeter() that returns the perimeter of the rectangle. D. Define a Square class that extends Rectangle. The class contains: A double data field named side to denote the side of the square. A constructor that creates a Square with the specified side. Pass the value of the side to Rectangles constructor: Rectangle(double side1, double side2). In other words, you have to call super and pass side for the two arguments: side1 and side2. A method getArea() that returns the area of the rectangle. A method getPerimeter() that returns the perimeter of the rectangle. Use the following code as a startup code 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(); } class Triangle extends GeometricObject { private double side1 = 1.0, side2 = 1.0, side3 = 1.0; /** Constructor */ public Triangle() { } /** Constructor */ public Triangle(double side1, double side2, double side3) { this.side1 = side1; this.side2 = side2; this.side3 = side3; } /** Override method findArea in GeometricObject */ public double getArea() { double s = (side1 + side2 + side3) / 2; return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3)); } /** Override method findPerimeter in GeometricObject */ public double getPerimeter() { return side1 + side2 + side3; } /** Override the toString method */ public String toString() { // Implement it to return the three sides return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3; } } class Test { public static void main(String[] args) { GeometricObject gObjectArray [] = new GeometricObject [4]; //Complete your code here } private static void printAreaAndPerimeter(GeometricObject gObject) { //Complete your code here } } For Question 3, you need to 1. Implement the classes Circle, EquilateralTriangle, Rectangle, and Square. 2. Implement the method printAreaAndPerimeter in the Test class that prints the area the perimeter of the passed GeometricObject. 3. In the Test class, create an array of GeometricObject of size 5, that contains the following elements: 3.1. The first element should be assigned to a Circle object: new Circle(5,5,5). 3.2. The second element should be assigned to a EquilateralTriangle object: new EquilateralTriangle(5). 3.3. The third element should be assigned to a Triangle object: new Triangle(5,5,5). 3.4. The fourth element should be assigned to a Rectangle object: new Rectangle(5,5) 3.5. The fifth element should be assigned to a Square object: new Square(5). 4. Pass each element in the array to printAreaAndPerimeter. 5. Compile, Run, and take a screenshot of the output and submit to Blackboard (you must submit the program regardless whether it complete or incomplete, correct or incorrect) 6. Check next page for submission template.

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

When is it appropriate to use a root cause analysis

Answered: 1 week ago

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago

Question

=+ Are there closed-shop requirements or practices?

Answered: 1 week ago