Menu

[Solved]Java Implement Triangle Class Triangle Represented Three Sides Therefore Class Three Priva Q37141948

(JAVA)

Implement a Triangle class. Any triangle can be represented byits THREE sides.

Therefore, your class will have THREE private member variables →side1, side2 and side3. Use the double data type to represent thetriangle sides.

In addition, please provide public methods that perform thefollowing FIVE tasks:

▪ An input method that obtains the appropriate values for thethree sides from the user. While entering the values of the threesides, please remember the triangle property that the sum of ANYtwo sides needs to be greater than the third side.

▪ A method that calculates and returns the Perimeter of theTriangle: The perimeter of a triangle is simply the sum of allthree sides of the triangle. ▪ An output method that prints allthree sides of the Triangle and other information (as show in thesample I/O) on the user screen. (No other methods should print outany information)

▪ A boolean method that determines whether the triangle isEquilateral: A triangle is equilateral if and only if all the THREEsides of the triangle are equal. If the triangle is equilateral, amessage conveying this should be sent to the screen. If thetriangle is not equilateral, then the corresponding message shouldbe sent to the screen (for example, if a = 3.4, b = 5.6 and c =23.7, then the output message should read → the triangle IS NOTequilateral).

• A method that calculates and returns the area of the triangle:The area of a triangle is given by the following formula: Given thethree sides of the triangle (say a, b and c), S = (a + b + c)/2.Then, Area = square root (S * (S – a) * (S – b) * (S – c)).

Write the corresponding main method that tests the Triangleclass and produce the following outputs:

Here is some sample output:

Please enter the value for side 1: 12.1

Please enter the value for side 2: 14.1

Please enter the value for side 3: 15. 1

The three sides that you entered are: 12.1, 13.1 and 14.1

The perimeter of the triangle is: 41.3 T

he triangle IS NOT equilateral.

The area of the triangle is: 80.11.

Expert Answer


Answer to (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore, your class will have T… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *