Question: Hello I am creating a java project that ask a user to input three seprate sides of a triangle and it will tell the user
Hello I am creating a java project that ask a user to input three seprate sides of a triangle and it will tell the user what type of triangle they have created. However I am stuggling to figure number 4 ("Not a Triangle because
Directions -->
This assignment is based on a classic problem in the book The Art of Software Testing(Myers, Sandler, & Badgett, 2011). By following the steps below using the test editor file from the Topic 1 assignment and a new "input.txt" file that will be created below, you will develop a program that reads three numbers on a line from the text file and interprets them as the length of three sides of a triangle. The program then examines the lengths of the lines and prints out:
1 "Equilateral" if the three lines are of equal (positive) length.
2 "Isosceles" if the two of the three lines are of equal (positive) length and the remaining
line is of different (positive) length that is shorter than the sum of the other two lines.
3 "Scalene" for any other valid triangle.
4 "Not a Triangle because
The program loops to read each line of input and processes it in turn. Use exception handling to trap input errors, and report them as "Not a Triangle because: <>".
Example Use Case: Create the "input.txt" file to contain the 3 lines below. Note that
the final file will contain many more than 3 lines.
1 1 1
2 2 1
2 x 3
Expected output:
Equilateral
Isosceles
Not a Triangle because: second line is not a number.
My Code So Far -->
public class Triangle {
// private static char in1;
int side1, side2, side3;
private static Scanner scanner;
Triangle (int a, int b, int c) {
side1 = a; side2 = b; side3 = c; }
boolean isScalene() {
return (side1 != side2 && side1 != side3); }
boolean isIsosceles() {
return (side1 == side2 && (side1 + side2)>side3 ||
side2 == side3 && (side2 + side3)>side1 ||
side1 == side3 && (side1 + side3)>side2); }
boolean isEquilateral() {
return (side1 == side2 && side1 == side3); }
public static void main(String[] args) throws IOException {
char in1;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("Enter the sides of triangle:");
int x,y,z;
scanner = new Scanner(System.in);
x=scanner.nextInt();
y=scanner.nextInt();
z=scanner.nextInt();
Triangle a, b, c;
a = new Triangle( x, y, z);
boolean flag=a.isIsosceles();
if(flag) {
System.out.println("it is Isosceles triangle"); }
else
System.out.println("it is not Isosceles triangle");
boolean flag1=a.isEquilateral();
if(flag1) {
System.out.println("it is Equilateral triangle"); }
else
System.out.println("it is not Equilateral triangle");
boolean flag2=a.isScalene();
if(flag2) {
System.out.println("it is Scalene triangle"); }
else
System.out.println("it is not Scalene triangle");
System.out.println("sides of triangle are:"+ a.toString());
System.out.println("Do you want to Continue [Y/N] ");
in1=(char)in.read();
} while(in1=='y'||in1=='Y'); }
public String toString() {
return + side1 + ", " + side2 + ", " + side3;
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
