Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design and write a Java class named Triangle (Triangle.java) that extends the GeometricObject class.The Triangle class contains: Three double data fields named side1, side2, and

Design and write a Java class named Triangle (Triangle.java) that extends the GeometricObject class.The Triangle class contains:

Three double data fields named side1, side2, and side3 with default values 3.0, 4.0, 5.0 to denote three sides of a 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 (getter) methods for all three data fields.

The mutator (setter) methods for all three data fields.

A method named getArea() that returns the area of this triangle. The formula for computing the area of a triangle is

A method named getPerimeter() that returns the perimeter of this triangle.

Overriding toString() method to return a string description for the triangle. o This overridden method must call the toString() method from its superclass (use keyword super) and adds the sides information to the returned string. (Please see the sample codes for more hints)

Write a testing Java application (TriangleTest.java) that tests ALL the constructors and methods mentioned above with at least the following features:

Prompting user to enter three sides of a triangle, a color, and a boolean value (for filled data field). Then, creating a Triangle object with these values.

Creating an object with actual type Triangle and declared type GeometricObject. Then, calling toString() method on it.

Calling toString() method on an object with actual type GeometricObject.

Writing a statement to downcast a GeometricObject instance. Writing a statement to upcast a Triangle instance.

I HAVE UPLOADED A PICTURE OF GEOMETRICOBJECT DOWN BELOW THERE IS NO NEED TO DO THAT AS I ALREADY HAVE IT DONE!

image text in transcribed

public class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated public Geometricobject() { date Created = new java.util.Date(); } public Geometricobject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; 3 public String getColor() { return color; } public void setColor (String color) { this.color = color; } public boolean isFilled() { return filled: } public void setFilled (boolean filled) { this.filled = filled; } public java.util.Date getDateCreated() { return dateCreated; ol public String toString() { return "created on + dateCreated + " color: " + color + " and filled: ". + filled; TI public class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated public Geometricobject() { date Created = new java.util.Date(); } public Geometricobject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; 3 public String getColor() { return color; } public void setColor (String color) { this.color = color; } public boolean isFilled() { return filled: } public void setFilled (boolean filled) { this.filled = filled; } public java.util.Date getDateCreated() { return dateCreated; ol public String toString() { return "created on + dateCreated + " color: " + color + " and filled: ". + filled; TI

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

4. What advice would you give to Carol Sullivan-Diaz?

Answered: 1 week ago