Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that takes lengths of three sides of a triangle and determines if the triangle is right ( one of its angles is
Write a program that takes lengths of three sides of a triangle and determines if the triangle is right one of its angles is degrees Start coding with RightTriangle.java provided. Keep in mind that lengths of the triangle sides can be entered in any possible order.
Your goal is to determine the largest side and check if the other sides fit the Pythagorean theorem equation. See Pythagorean theorem here
Example: Determine if a Triangle is a Right Triangle Given the Length of SidesLinks to an external site.
Example: Determine if a Triangle is a Right Triangle Given the Length of Sides
If the triangle is a right one, output must contain word RIGHT in all caps and the Pythagorean theorem equation as an explanation, see samples below:
Sample run #:
Enter the size of the first side of the triangle
Enter the size of the second side of the triangle
Enter the size of the third side of the triangle
This is a RIGHT triangle because
Sample run #:
Enter the size of the first side of the triangle
Enter the size of the second side of the triangle
Enter the size of the third side of the triangle
This is a RIGHT triangle because
If the triangle is not a right one, output must contain word NOT in all caps, see sample below:
Sample run #:
Enter the size of the first side of the triangle
Enter the size of the second side of the triangle
Enter the size of the third side of the triangle
This is NOT a right triangle.
In addition, your program must prevent zero and negative values to be used for calculations. When nonpositive number is entered, the program must quit right away ;) The error message must contain word ERROR in all caps. See samples below:
Sample run #:
Enter the size of the first side of the triangle
ERROR: Side size must be a positive number! Quitting...
Sample run #:
Enter the size of the first side of the triangle
Enter the size of the second side of the triangle
ERROR: Side size must be a positive number! Quitting...
Sample run #:
Enter the size of the first side of the triangle
Enter the size of the second side of the triangle
Enter the size of the third side of the triangle
ERROR: Side size must be a positive number! Quitting...
Test cases
import java.ioByteArrayInputStream;
import java.ioByteArrayOutputStream;
import java.ioPrintStream;
import java.ioPrintWriter;
import java.util.regex.Pattern;
public class TestRightTriangle
public static boolean testsPrintWriter outputStream
int count ;
int expectedCount ;
outputStream.printr
Tests for RightTriangle r
;
Test
outputStream.printr
Test r
;
String sep System.lineSeparator;
String userInput String.formatss sep, sep;
String expectedOutput siERROR.;
outputStream.printr
Input:r
;
outputStream.printlnuserInput;
outputStream.printr
Expected output must fit RegEx:r
;
outputStream.printlnexpectedOutput;
PrintStream standard System.out;
ByteArrayInputStream bais new ByteArrayInputStreamuserInputgetBytes;
System.setInbais;
ByteArrayOutputStream baos new ByteArrayOutputStream;
PrintStream printStream new PrintStreambaos;
System.setOutprintStream;
RightTriangle.mainnull;
Systemout.printlnEnd of Test";
String lines baos.toStringsplitSystemlineSeparator;
String actual baos.toString;
printStream.close;
outputStream.printr
Actual Output:r
;
outputStream.printlnactual;
outputStream.println;
ifPatternmatchesexpectedOutput actual
outputStream.printfssr
"RightTriangle TEST first value negative", "PASSED";
count;
else
outputStream.printfssr
"RightTriangle TEST first value negative", "FAILED";
Test
outputStream.printr
Test r
;
userInput String.formatss sep, sep;
expectedOutput siERROR.;
outputStream.printr
Input:r
;
outputStream.printlnuserInput;
outputStream.printr
Expected output must fit RegEx:r
;
outputStream.printlnexpectedOutput;
bais new ByteArrayInputStreamuserInputgetBytes;
System.setInbais;
b
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