Question: Triangle Class as a Subclass of GeometricObject Submit Triangle.java, GeometricObject.java, Lab4.jar, screen shots of results, and this word file (completed version) Problem Description: Design, implement,

Triangle Class as a Subclass of GeometricObject

Submit Triangle.java, GeometricObject.java, Lab4.jar, screen shots of results, and this word file (completed version)

Problem Description:

Design, implement, and test Triangle class that extends GeometricObject in text book.

The Triangle class contains:

  • Three double data fields named side1, side2, and side3 (default values 1.0) to denote three sides of the triangle.
  • A default constructor (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 isEquilateral() that returns true if the triangle is equilateral.
  • A method named isIsosceles() that returns true if the triangle is isosceles.
  • A method named toString() that returns a string description for the triangle.

For the formula to compute the area of a triangle, see Exercise 5.19. The toString() method is implemented as follows:

return "Triangle: side1 = " + side1 + " side2 = " + side2 +

" side3 = " + side3;

  1. Design. Draw the UML class diagram for Triangle and GeometricObject classes with class inheritance. Implement the Triangle class. Write a test program that creates a Triangle object with sides 1, 1.5, 1, color yellow and filled true, and displays the area, perimeter, color, and whether filled or not.

GeometricObject

- String color = "white";

- boolean filled;

- java.util.Date dateCreated;

+ GeometricObject ()

+ GeometricObject (Color c, boolean f)

+ getColor() : String

+ setColor(String color) : voif

+ isFilled() : boolean

+ setFilled(boolean filled) :void

+getDateCreated():java.util.Date

+toString(): String

+equals(GeometricObject o): boolean

Complete the UML class diagram here

  1. Implement Triangle class as a subclass of GeometricObject class.

Coding: (Copy and Paste Source Code here. Format your code using Courier 10pts)

  1. Test your program. Explain how did you test your program and copy your test code here.

  1. Running result: Copying the running result here.

Remark:

A triangle in which all three sides have equal lengths is called an equilateral

triangle and a triangle in which two sides have equal lengths is called isosceles.

Don't forget to answer the sub-questions :)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!