Question: Write the code in JAVA Design a class named Triangle that extends GeometricObject ( as shown below ) . The class should contain the following
Write the code in JAVA
Design a class named Triangle that extends GeometricObject as shown below The class should contain the following three private double data fields: side side side with default values to denote three sides of the triangle.
In addition, the class should have the following constructors and methods:
A noarg constructor that initializes all three sides to
A constructor that creates a triangle with the specified side side and side
The setter methods for three data fields.
The getter methods for three data fields.
A method named getPerimeter that returns the perimeter of this triangle.
A method named toString that returns a string description for the triangle.
Write a test program that does the following tasks:
Prompts the user to enter three sides of the triangle. The program creates a Triangle object with these sides. Prompt the user to enter a color and a Boolean value to indicate whether the triangle is filled. Use these two input values to set the data fields color and filled.
Invoke the Triangle objects getPerimeter and toString methods.
public class GeometricObject
private String color "white";
private boolean filled;
private java.util.Date dateCreated;
Construct a default geometric object
public GeometricObject
dateCreated new java.util.Date;
Construct a geometric object with the specified color
and filled value
public GeometricObjectString 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 setColorString 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 setFilledboolean filled
this.filled filled;
Get dateCreated
public java.util.Date getDateCreated
return dateCreated;
Return a string representation of this object
public String toString
return "created on dateCreated
color: color
and filled: filled;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
