Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I Design a class named Triangle that extends GeometricObject. The class contains

ID: 663894 • Letter: I

Question

I

Design a class named Triangle that extends GeometricObject. The class contains:

Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle.

A no-argument constructor that creates a default triangle.

A constructor that creates a triangle with the specified side1, side2, and side3.

Note: constructors invokes the setColor() & setFilled() methods of the GeometricObject.

The accessor methods for all three data fields.

A method named getArea() that returns the area of the triangle. The formula to compute area of the triangle is:

s = (side1 + side2 + side3)/2;

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

A method named toString() that returns a string description for the triangle.

II

Modify the toString() methods of the Rectangle and Circle classes to return object information as specified in the sample output.

III

Write a test program named myShapes4 that populate an ArrayList of type GeometricObject with several Circle, Rectangle, and Triangle objects.

IV

Traverse the ArrayList and display the information of objects stored with their areas and perimeters. Also, compute and display the total area and total perimeter of all objects.

Sample output

         Object number: 1       Circle Information
         Date:          Fri Jun 19 09:17:52 EDT 2015
         Radius:        0.0
         Perimeter:     0.0
         Area:          0.0
         Color:         white
         Filled:        false

         Object number: 2       Triangle Information
         Date:          Fri Jun 19 09:17:52 EDT 2015
         Side1:         3.0
         Side2:         4.0
         Side3:         5.0
         Perimeter:     12.0
         Area:          6.0
         Color:         Uncolored
         Filled:        false

         Object number: 3       Rectangle Information
         Date:          Fri Jun 19 09:17:52 EDT 2015
         Width:         6.0
         Height:        7.0
         Perimeter:     26.0
         Area:          42.0
         Color:         Green
         Filled:        true

        The total area for all shapes is:       48.0

        The total perimeter for all shapes is: 38.0

Sample output

         Object number: 1       Circle Information
         Date:          Fri Jun 19 09:17:52 EDT 2015
         Radius:        0.0
         Perimeter:     0.0
         Area:          0.0
         Color:         white
         Filled:        false

         Object number: 2       Triangle Information
         Date:          Fri Jun 19 09:17:52 EDT 2015
         Side1:         3.0
         Side2:         4.0
         Side3:         5.0
         Perimeter:     12.0
         Area:          6.0
         Color:         Uncolored
         Filled:        false

         Object number: 3       Rectangle Information
         Date:          Fri Jun 19 09:17:52 EDT 2015
         Width:         6.0
         Height:        7.0
         Perimeter:     26.0
         Area:          42.0
         Color:         Green
         Filled:        true

        The total area for all shapes is:       48.0

        The total perimeter for all shapes is: 38.0

Explanation / Answer

Triangle program:

Test case: