Question: 4. Write an inner public class named Triangle (not static). In this class, 1) Write three private instance variables, a, b, and c. Each instance

4. Write an inner public class named Triangle (not static). In this class, 1) Write three private instance variables, a, b, and c. Each instance variable represents the length of a line (type double). (6 pts) 2) Write a constructor method to initialize each instance variable. (3 pts) 3) Write a public get/set method for each instance variable. (6 pts) 4) Write a public method named is_triangle() to calculate whether you can form a valid triangle with these three lines. Return true if a valid triangle can be formed, return false otherwise. Hint: the length of a side must be less than the combined length of the other two sides. (10 pts) 5) Write a public method named get_triangle_type(). In this method, check whether you can form a valid triangle with these three lines by using the method, is_triangle(). If no, return "cannot form a triangle". If yes, determine whether the triangle is equilateral, isosceles, or scalene. Return the result. Hint: An equilateral triangle has 3 equal sides. An isosceles triangle has 2 equal sides. A scalene triangle has 3 different sides. (15 pts) Test case: 1) Create two objects of the Triangle class, triangle1 with lines of length 20, 40.5, and 15.5, and triangle2 with lines of length 20.5, 15, 20.5. 2) For each object, call is_triangle() and get_triangle_type() respectively

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!