1. Member
Join Date
Apr 2017
Posts
8
Rep Power
0

## I need help with my homework please!

this is the homework
Triangles can be classified in a number of ways by considering the relative sizes of either their
sides or their angles.
Side Classifications:
1. equilateral – all sides are equal
2. isosceles – exactly two sides are equal
3. scalene – no sides are equal
Side classifications are done by comparing the length of the three sides of the triangle.
Angle Classifications:
1. right – the largest angle is a right angle (i.e., 90°)
2. acute – the largest angle is less than a right angle
3. obtuse – the largest angle is greater than a right angle
If the three sides of a triangle are known, the Pythagorean Theorem can be used to classify the
triangle as right, obtuse, or acute.
Recall: The Pythagorean Theorem states that, in a right triangle, the square of the largest side is
equal to the sum of the squares of the other two sides. As an equation,
c2=a2b2
If the triangle is not a right triangle, this relationship can still be used to determine if the triangle is
acute or obtuse.
Problem Statement
Write a program that will read an arbitrary number of sets of triangle sides using only integer
values. The program should:
1. Prompt the user for sets of numbers and process them until the user submits the numbers
0 0 0, which will terminate the program.
2. For each set of three numbers, the program should print the values read.
3. For each set of three numbers, the program should decide if the numbers represent the
sides of a valid triangle.
4. If the numbers could not represent a valid triangle, display an appropriate error message.
5. If the numbers are valid, the program should determine, and display, the:
(a) side classification of the triangle – equilateral, isosceles, or scalene
(b) angle classification of the triangle – right, acute, or obtuse
ICS3x Assignment – Methods – Triangle Classification Nov 24, 2010
Sample Input & Output
Input from the user is indicated by bolded text.
Provide three side lengths – 0 0 0 to terminate.
3
5
4
3 5 4 Triangle possible: scalene and right.
Provide three side lengths – 0 0 0 to terminate.
5
2
5
5 2 5 Triangle possible: isosceles and acute.
Provide three side lengths – 0 0 0 to terminate.
-7
1
2
-7 1 2 Triangle cannot be formed.
Provide three side lengths – 0 0 0 to terminate.
0
0
0
0 0 0 Program was terminated by user.

(You can only use input/output, calculations, variables, decisions, and loops)

2. Member
Join Date
Apr 2017
Posts
8
Rep Power
0

## Re: I need help with my homework please!

class TriangleClassification
{

public static void main (String[] args)
{

int num1, num2, num3;

num1 = In.getInt();
num2 = In.getInt();
num3 = In.getInt();

if (num1==num2 && num3==num2 && num1==num3){
System.out.println("Its an Equilateral triangle");
}else if ((num1==num3 && num3!=num2) || (num2==num3 && num1!=num2) || (num1==num2 && num2!=num3)){
System.out.println("Its an Isosceles triangle.");
}else if (num1!=num2 && num2!=num3 && num1!=num3){
System.out.println("Its a Scalene triangle.");

}
}
}
i got this far i need help with the angles part

3. ## Re: I need help with my homework please!

[code]
[/code]

to get highlighting and preserve formatting.

4. Member
Join Date
Apr 2017
Posts
8
Rep Power
0

## Re: I need help with my homework please!

Originally Posted by Norm

[code]
[/code]

to get highlighting and preserve formatting.
ok thx sry i am still new to java and what i need is the (b) angle classification of the triangle – right, acute, or obtuse
Java Code:
```public static void main (String[] args)
{

int num1, num2, num3;

num1 = In.getInt();
num2 = In.getInt();
num3 = In.getInt();

if (num1==num2 && num3==num2 && num1==num3){
System.out.println("Its an Equilateral triangle");
}else if ((num1==num3 && num3!=num2) || (num2==num3 && num1!=num2) || (num1==num2 && num2!=num3)){
System.out.println("Its an Isosceles triangle.");
}else if (num1!=num2 && num2!=num3 && num1!=num3){
System.out.println("Its a Scalene triangle.");```

5. ## Re: I need help with my homework please!

need is the (b) angle classification of the triangle – right, acute, or obtuse
What are the rules to determine that? You will need those before trying to write the code to implement them.

The posted code has lost its formatting. Be sure to preserve the indentations when posting code.
Last edited by Norm; 04-13-2017 at 01:27 PM.

6. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
26

## Re: I need help with my homework please!

Java Code:
`if (num1==num2 && num3==num2 && num1==num3)`
You can shorten that, by the way.
If num1 == num2, and num3 == num2, then num1 has to equal num3, so no need to do that last check.

7. Member
Join Date
Apr 2017
Posts
8
Rep Power
0

## Re: I need help with my homework please!

all i need my program to do now is output this but i dont know what code to write
Provide three side lengths – 0 0 0 to terminate.
3
5
4
3 5 4 Triangle possible: scalene and right.

8. ## Re: I need help with my homework please!

Also posted at: The Angle Classification Of The Triangle Right, Acute, Or Obtuse Hmwrk - Java | Dream.In.Code

what code to write
Before writing any code, you need to describe what the rules are to solve the problem.

9. Member
Join Date
Apr 2017
Posts
8
Rep Power
0

## Re: I need help with my homework please!

ohh well you first ask the user to write 3 intergers down and then after you do that the program will output the results (only positive integers)
rules:(You can only use input/output, calculations, variables, decisions, and loops)

10. ## Re: I need help with my homework please!

Ok if those are all the rules you need for the program,
are you having any problems writing the code for those rules?

If you are having problems, post the rule you are trying to write the code for, the code that you are working on for that rule and ask some questions about the problems you are having.

11. Member
Join Date
Apr 2017
Posts
8
Rep Power
0

## Re: I need help with my homework please!

Originally Posted by Norm
Ok if those are all the rules you need for the program,
are you having any problems writing the code for those rules?

If you are having problems, post the rule you are trying to write the code for, the code that you are working on for that rule and ask some questions about the problems you are having.

I just need to how to write the code so it can ask user for input and then output what type of triangle it is so basicly i need help on the math and code

12. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
26

## Re: I need help with my homework please!

That's several things.

So start from the beginning.
Write the code to ask the user for the numbers.

ETA: you almost have that in your original code, it's just not formatted the same as the output you want.

13. ## Re: I need help with my homework please!

code so it can ask user for input
Isn't that done already by lines 12 to 17?

output what type of triangle it is
Ok, that is where you need the rules to use for testing the user's input and determining the type of triangle.
What does the code on lines 19 to 24 do?
What more do you need besides those lines of code?

Make a list of the types of triangles and the rules to use to determine if the input matches any of those types.

14. Member
Join Date
Apr 2017
Posts
8
Rep Power
0

## Re: I need help with my homework please!

The code i posted up there is the stuff i finished
What i need is code that will ask user to type 3 positive intergers then output if the trangle is right,acute,obtuse

15. ## Re: I need help with my homework please!

ask user to type 3 positive intergers
You should be able to copy the statements on lines 12 to 17 to do that.

output if the trangle is right,acute,obtuse
What are the rules to determine each of those
rules for right?
rules for acute?
rules for obtuse?

You need to work out the rules (how would you do it with paper and pencil)
before trying to write the code.

For sample code for another set of rules see statements on lines 19 to 24.

16. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
26

## Re: I need help with my homework please!

OK.
So start from the beginning.
Write the code to get the three ints, which should just be a case of modifying part of the above code

17. Member
Join Date
Apr 2017
Posts
8
Rep Power
0

## Re: I need help with my homework please!

Java Code:
```if (num1*num1 + num2*num2) == num3) || (num2*num2 + num3*num3) == num1) || (num3*num3 + num1*num1) == num2) {
System.out.println("Its a right angle"); }```
What wrong with this code i get error
Java Code:
```5 errors found:
File: C:\Users\kirubarajah\Music\DR.Java\TriangleClassification.java  [line: 28]
Error: Syntax error on token "==", invalid (
File: C:\Users\kirubarajah\Music\DR.Java\TriangleClassification.java  [line: 28]
Error: Syntax error on token ")", delete this token
File: C:\Users\kirubarajah\Music\DR.Java\TriangleClassification.java  [line: 28]
Error: Syntax error on token ")", delete this token
File: C:\Users\kirubarajah\Music\DR.Java\TriangleClassification.java  [line: 28]
Error: Syntax error, insert "AssignmentOperator Expression" to complete Assignment
File: C:\Users\kirubarajah\Music\DR.Java\TriangleClassification.java  [line: 28]
Error: Syntax error, insert ";" to complete Statement```
this is the error

18. ## Re: I need help with my homework please!

Hint:
Java Code:
`if ((condition1) || (condition2)) {`
db

19. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: I need help with my homework please!

Did your teacher provide an algorithm or a hint on how to distinguish triangle types? After all, this is supposed to be a programming assignment, not a math exercise. Especially for the acute, obtuse, and right triangle test.

Regards,
Jim
Last edited by jim829; 04-14-2017 at 05:03 PM.