Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The goal of this lab is to write a program ThreeNumbers for checking various conditions of three input numbers in three different settings. The program
The goal of this lab is to write a program ThreeNumbers for checking various conditions of three input numbers in three different settings. The program uses three methods for the three tasks. The first one, order, receives three int values a, b, and c. The method computes the maximum, the minimum, and the median of the three values and report the results. For the maximum and the minimum, you can use the Math methods Math.max and Math.min. Since these methods take two parameters, it is necessary to use these twice each to compute the maximum and the minimum of three items. You can compute the median by first assuming that the median is one of the values, say a, and then check whether there is a need to change it to b or c. Such situations occur when (1) both b and c are greater than a and (2) both b and c are smaller than a. The median is the smaller of b and c for (1) and the greater of b and c for (2). The second method, angles, receives three double values, a, b, c. Then, assuming that these values represent the three angles of a triangle, the method reports what types of triangle they represent. First, if one of the values is negative or the sum of the three is not equal to 180, the trio cannot repressent a triangle. If that is the case, the method states that it is not a triangle and returns. After this test, the method executes two sets of tests. The first set of tests is whether the triangle is a perfect triangle, an isosceles triangle, or neither type. This is possible by checking whether the three values are all equal, and if not, whether a pair of them are equal to each other. The second set of tests is whether the triangle is an obtuse triangle, a right-angled triangle, or an acute triangle. You can accomplish this by testing whether any angle is greater than 90, if not whether any angle is equal to 90. The third method, sides, receives three double values, a, b, c. Then, assuming that these values represent the three edges of a triangle, the method reports what types of triangle they represent. First, if one of the values is negative or one value is greater than the sum of the other two, the trio cannot repressent a triangle. If that is the case, the method states that it is not a triangle and returns. After this test, the method executes, like before, two sets of tests. The first set of tests is whether the triangle is a perfect triangle, an isosceles triangle, or neither type. This is possible by checking whether the three values are all equal, and if not, whether a pair of them are equal to each other. The second set of tests is whether the triangle is an obtuse triangle, a right-angled triangle, or an acute triangle. To conduct this test, the method computes the squares of the three sides and store them in some variables, say aSquare, bSquare, and cSquare. Then it checks whether one square is equal to the sum of the other two squares, if not whether one square is greater than the sum of the other two squares. The former occurs for a right-angled triangle, the latter occurs for an obtuse triangle. If neither occur for an acute triangle The main method of the program receives three integers from the user and calls order with the three values. Similarly, it receieves three floating point numers from the user and calls angles with the three values. Finally, it does the same for sides. Below is a sample execution of the program, where the characters in blue represent the user input. The characters in blue represent the user input. Enter three integers: 10 20 -30 The maximum is 20. 3 The minimum is -30. The median is 10. 5 Enter three angles: 90 45 45 A non-perfect isosceles triangle. A right-angled triangle. Enter three sides: 3 4 5Not an isosceles triangle. A right-angled triangle. Here is another CON Enter three integers: 134 5444444 33 The maximum is 5444444. The minimum is 33. The median is 134. Enter three angles: 34 76 99 6 Not a triangle. 7 Enter three sides: 100 200 301 Not a triangle
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started