Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design and implement a class named Triangle. The class contains: Three double data fields named side 1 , side 2 , and side 3 with

Design and implement a class named Triangle. The class contains:
Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides (lengths) of the triangle. Sides are in no particular order.
The accessor (getters) methods for all three data fields.
Mutator (setters) methods for all three fields. Remember you can't except a zero or negative numbers as sides.
A no-arg constructor that creates a default triangle.
A constructor that creates a triangle with the specified side1, side2, and side3.
A method named isValid() that returns true or false if the sides form a valid triangle. Remember the sides are not in any particular order and that a triangle is not valid if you have a side that is longer than the sum of the other two. Think about it. Can you have a triangle if the sides are 1,100,2?
A method named getArea() that returns the area of this triangle. Use Heron's Formula to compute the area. If the triangle is not valid, return -1.
A method named getPerimeter() that returns the perimeter of this triangle. If the the triangle is not valid, return -1.
A method named toString() that returns a string description for the triangle. This method should return something like Triangle: side1=10, side2=5, side3=7
Make sure that when bad triangle sides are used to construct the triangle that the appropriate error message(s) are given. If you attempt to get the triangle's area and perimeter, output the appropriate error messages if the triangle is not valid

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago