Introduction to JAVA Programming Assignment 3 - Triangle Inequality Theorem - a program that uses a method with parameters and return values.
Submission:
Submit a screenshot of your code and a screenshot of the output as an example. We will discuss how to submit a zip file in class.
Write a program that will check three user input values to see if they can be used to create a triangle. Do this by using the triangle inequality theorem, which says: Any side of a triangle must be shorter than the sum of the other two sides.
So, if the sides are a, b, and c, all of the following must be true:
a + b > c
b + c > a
a + c > b
The method you will use to test this can be done like this (but you don't have to use this):
public static boolean triangleTest(int a, int b, int c) {
// It will need some logic and if statements,
// and you will need to make sure there is a return statement
// which gives back either true if the sides will create a triangle,
// or false if not.
}
If you are having trouble, break the problem into steps:
1. Create a boolean method that takes 3 integers as arguments.
a. You can just return false if you want to get the flow of the code.
b. Or you can put the if statement logic in place.
2. Call the method with 3 parameters that you hard code.
a. For example: boolean test = triangleTest(3, 4, 5);
3. Make sure the method executes and returns the correct value to your main code.
So, also run the test with some numbers that don't work (e.g., 4, 0, 3).
4. Print out the value that is returned along with the three numbers.
5. Once the logic is working, you can add the user input to get the three numbers from the user.
Bonus Challenge:
Test if the numbers will work to create a right triangle!!!