Question: Java Program Design three classes: 1. A Circle class as described above with a default radius of 1.0 2. A Rectangle class as described above
Java Program
Design three classes:
1. A Circle class as described above with a default radius of 1.0
2. A Rectangle class as described above with a default width and height of 1.0
3. A class named Triangle that also extends GeometricObject. The class contains:
Three data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle.
A no-arg constructor that creates a default triangle.
A constructor that creates a triangle with the specified side1, side2, and side3.
The accessor methods for all three data fields.
A method named getArea() that returns the area of this triangle.
A method named getPerimeter() that returns the perimeter of this triangle.
A method named toString() that returns a string description for the triangle.
The area of a triangle can be calculated with this formula: A = sqrt(s(s-a)(s-b)(s-c)) where a, b, and c are the lengths of the sides and s is half of the perimeter.
Here is the code for Geometric Object:
public class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; private String name = "noname"; /** Construct a default geometric object */ public GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with the specified color * and filled value */ public GeometricObject(String color, boolean filled, String name) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; this.name = name; } /** 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, its 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; } /** Return name */ public String getName() { return name; } /** Set a new name */ public void setName(String name) { this.name = name; } /** Return a string representation of this object */ public String toString() { return "created on " + dateCreated + " color: " + color + " and filled: " + filled; } } Write a test program that creates Circle, Rectangle and Triangle objects. Your test program will be very extensive.
Make sure you test all the constructors.
Make sure you test all the methods.
Create tests that will demonstrate polymorphism. You can do this by creating an ArrayList of Geometric objects then proving that if you invoke the getArea() or getPerimeter() methods, the correct version of the method will be executed.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
