Write the method called printTriangleType referred to in Self-Check Problem 25. This method accepts three integer arguments

Question:

Write the method called printTriangleType referred to in Self-Check Problem 25. This method accepts three integer arguments representing the lengths of the sides of a triangle and prints the type of triangle that these sides form. Here are some sample calls to printTriangleType:

printTriangleType(5, 7, 7);

printTriangleType(6, 6, 6);

printTriangleType(5, 7, 8);

printTriangleType(2, 18, 2);

The output produced by these calls should be

isosceles
equilateral

scalene
isosceles

Your method should throw an IllegalArgumentException if passed invalid values, such as ones where one side’s length is longer than the sum of the other two, which is impossible in a triangle. For example, the call of printTriangleType(2, 18, 2); should throw an exception.


Data from Self check Problem 25

Consider a method printTriangleType that accepts three integer arguments representing the lengths of the sides of a triangle and prints the type of triangle that these sides form. The three types are equilateral, isosceles, and scalene. An equilateral triangle has three sides of the same length, an isosceles triangle has two sides that are the same length, and a scalene triangle has three sides of different lengths.

However, certain integer values (or combinations of values) would be illegal and could not represent the sides of an actual triangle. What are these values? How would you describe the precondition(s) of the printTriangleType method?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: