Define the triangle class with three sides. in a triangle, the sum of any two sides is greater than the other side. the triangle class must adhere to this rule. create the illegaltriangleexception class, and modify the constructor of the triangle class to throw an illegaltriangleexception object if a triangle is created with sides that violate the rule,
Answers
Answered by
0
triangle in two dimensions is defined by three two-dimensional vertices (points). This homework assignment is based upon first defining a Point class and then using it to create a Triangle class that represents triangles. A rectangle is defined by two points for the lower left corner and the upper right corner. You will also define the Rectangle class.
Designing the Classes:
Study the Javadoc documentation for the Triangle class and the Point class. This documentation provides the specification for these classes.
The constructor for the Point class will receive two doubles, representing the X and Y coordinates of the Point being constructed. Add a method to show (print) an instance of the Point class, i.e., the coordinates of a single point. This class will not need any other methods.
The constructor for the Triangle class will receive three Point objects representing the three vertices of the triangle. Note that the three arguments to the constructor can be in any order. This class should also be able to return the area, perimeter, and lengths of the three sides of the triangle. Your definition for the class must include the declaration of the variables in the class along with the constructor, the area method, the perimeter method, and three methods for the lengths of the sides. The area is defined as such:
Area = SQRT(s (s - a)(s - b)(s - c)),
where a, b, and c are the lengths of the three sides of the triangle
and s is the semiperimeter:
s = (a + b + c)/2
Designing the Classes:
Study the Javadoc documentation for the Triangle class and the Point class. This documentation provides the specification for these classes.
The constructor for the Point class will receive two doubles, representing the X and Y coordinates of the Point being constructed. Add a method to show (print) an instance of the Point class, i.e., the coordinates of a single point. This class will not need any other methods.
The constructor for the Triangle class will receive three Point objects representing the three vertices of the triangle. Note that the three arguments to the constructor can be in any order. This class should also be able to return the area, perimeter, and lengths of the three sides of the triangle. Your definition for the class must include the declaration of the variables in the class along with the constructor, the area method, the perimeter method, and three methods for the lengths of the sides. The area is defined as such:
Area = SQRT(s (s - a)(s - b)(s - c)),
where a, b, and c are the lengths of the three sides of the triangle
and s is the semiperimeter:
s = (a + b + c)/2
Similar questions