Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

What are the causes and consequences of abuse of power?

Answered: 1 week ago