Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We are in the middle of the if statement chapter. I mostly have the first task d

ID: 3550398 • Letter: W

Question

We are in the middle of the if statement chapter. I mostly have the first task done, I'm just having a difficult time ordering the if statements correctly to fit with the conditions. Please remember for task one that there needs to be code to read a right triangle, as well as an isosceles triangle (same with acute and obstuse), because that is where I'm having the most trouble.


I'm confused by the entire second task.


Thanks ahead of time.


Read three sides (integers) and identify the type of triangle. When the first side length is input, check whether the value is odd or even and print it out. When the second side length is input, check whether the side is equal/longer/shorter than the first side and print it out. When the third side is input, compare all three values and print out three sides from longest to the shortest order. Once the three sides are input, identify a type of triangle from the list below. The definitions of triangle types are also described. Types: Equilateral, Right Isosceles, Obtuse Isosceles, Acute Isosceles, Right, (not isosceles) Obtuse, (not isosceles) Acute, (not isosceles) Invalid Equilateral triangle has all three sides the same length. Isosceles triangle has two sides with the same length, and it is sub-grouped into right isosceles, obtuse isosceles, and acute isosceles based on the angles. Right triangle has one 90 angle, and a2 = b2 + c2 where a is the longest side. Obtuse triangle has one angle that is greater than 90 degree, and a2 b2 + c2 where a is the longest side. Invalid is the case when the longest side a is bigger than the total of the other two sides (b and c). When the input is invalid (zero, negative, non-integer, etc.), print out "Invalid Data Input", and do nothing else. Read three points (X and Y positions) and identify the type of triangle. The user inputs the X and Y values in a single line for each point. Then each line will be subdivided into two Strings and converted to two integers. Once three points are input, calculate the length of sides and identify a type of triangle from the same list in the The following methods may help on implementing this part. Look at the API for more details on String, Integer, and Math classes. substring(int) : return a substring after the position substring(int, int) : return a substring from the start position to the end position Math.sqrt(double): return the square root value. indexOf (String): return the first position matching to the String pattern Use only the Java statements that have been covered in class to date. DO NOT use any other statements (loop, array, break, etc.). If in doubt, ask. If you use them, then you lose the points of task. Complete each task one by one. The Task2 has only 3 point, but it is a hard question. If your program file does not run correctly, then you may lose all 15 points. If your program works only for the Task1 without Task2, then you get 12 points out of 15. Example Execution: The following is an example input and output. The input is shown in red. Make your own questions rather than this example.

Explanation / Answer


import java.util.Scanner;

public class TriangleType {

public static String showType(int k)

{

if ( (k/2)*2 == k )

return("Even");

else

return("Odd");

}

static String getType(int a, int b, int c)

{

if(a<=0||b<=0||c<=0)

return "Invalid input";


if(a==b&&b==c&&c==a)

return "EQUILATERAL";

else if((a==b)||(b==c)||(c==a))

return "ISOSCELES";

else

return "InValid";

}

static String angleTriangle(int a,int b,int c)

{

if(a>b&&a>c)

{

if((a*a)==(b*b)+(c*c))

{

return ("It is a right-angled triangle");

}

elseif(b>c&&b>a)

{

if((b*b)==(c*c)+(a*a))

return ("It is a right-angled triangle");

}

elseif(c>a&&c>b)

{

if((c*c)==(a*a)+(b*b))

return("It is a right-angled triangle");

}

else

{

return "It is not a Right-angled Trianlge";

}

}

}

public static void main(String[] args)

{

int a=0,b=0,c=0;

System.out.println("Enter Side of triangle:");

Scanner in = new Scanner(System.in);

a = in.nextInt();

System.out.println((showType(a));

System.out.println("Enter Side of triangle:");

Scanner in = new Scanner(System.in);

b = in.nextInt();

System.out.println((showType(b));

System.out.println("Enter Side of triangle:");

Scanner in = new Scanner(System.in);

c = in.nextInt();

System.out.println((showType(c));

System.out.println(getType(a,b,c));

System.out.println(angleTriangle(a,b,c));


}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote