Question: + numOfTriangles: int + Triangle ( ) + Triangle ( oppositeSide : int, adjacentSide : int, hypotenuse: int ) + getOppositeSide ( ) : int
numOfTriangles: int
Triangle
TriangleoppositeSide : int, adjacentSide : int, hypotenuse: int
getOppositeSide: int
setOppositeSideoppositeSide: int : void
getAdjacentSide: int
setAdjacentSideadjacentSide: int : void
getHypotenuse: int
setHypotenusehypotenuse: int : void
getNumOfTriangles: int
isRightAngled: Boolean
toString: String
Create a Java program called "TestTriangle". Inside this program, implement the class "Triangle" as shown in the UML Class diagram above.
You must implement the "Triangle" class strictly according to its UML onetoone do not include anything extra, do not miss any data fields or methods
The method isRightAngled returns true if the triangle is a right angled, otherwise it returns false. The logic for checking a rightangled triangle is:
"Sum of squares of two small sides adjacent and opposite should be equal to the square of the longest side hypotenuse
Add comments to your program mark where data fields, constructors, getters, setters, methods, toString are
Create two Triangle objects: one using noargs ie default constructor and one from the constructor with all fields. ie overloaded
Print the contents of both objects using toString method.
Part : Working with Class Objects points
Inside the "TestTraingle", do the following steps onebyone:
i The program should randomly pick a number between to and store it
ii The program should then create an array of triangle objects equal to the random number.
iii. The program should construct the triangle objects in the array by invoking the overloaded constructor.
iv The program should randomly assign values for the data fields in range to
v The program should then display the total number of triangle objects created by invoking the getNumOfTriangles method.
vi The program should then display the values of opposite side, adjacent side and hypotenuse only for those triangle objects that are rightangled. If none of the triangle objects are rightangled, it should display a message "There is no rightangled triangles in the object array".
numOfTriangles: int
Triangle
TriangleoppositeSide : int, adjacentSide : int, hypotenuse: int
getOppositeSide: int
setOppositeSideoppositeSide: int : void
getAdjacentSide: int
setAdjacentSideadjacentSide: int : void
getHypotenuse: int
setHypotenusehypotenuse: int : void
getNumOfTriangles: int
isRightAngled: Boolean
toString: String
Create a Java program called "TestTriangle". Inside this program, implement the class "Triangle" as shown in the UML Class diagram above.
You must implement the "Triangle" class strictly according to its UML onetoone do not include anything extra, do not miss any data fields or methods
The method isRightAngled returns true if the triangle is a right angled, otherwise it returns false.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
