Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

How to reverse a Armstrong number by using double linked list ?

Answered: 1 week ago

Question

Question What are the requirements for a safe harbor 401(k) plan?30

Answered: 1 week ago