Results 1 to 19 of 19
  1. #1
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default 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. #2
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Re: I need help with my homework please!

    class TriangleClassification
    {

    public static void main (String[] args)
    {


    int num1, num2, num3;






    System.out.println("Enter your first number.");
    num1 = In.getInt();
    System.out.println("Enter your second number.");
    num2 = In.getInt();
    System.out.println("Enter your third number.");
    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. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: I need help with my homework please!

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default Re: I need help with my homework please!

    Quote Originally Posted by Norm View Post
    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/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;
    
    
    
    
    
    
    System.out.println("Enter your first number.");
    num1 = In.getInt();
    System.out.println("Enter your second number.");
    num2 = In.getInt();
    System.out.println("Enter your third number.");
    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. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default 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. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default 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. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default Re: I need help with my homework please!

    Quote Originally Posted by Norm View Post
    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. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default 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. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default 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
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default 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. #18
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: I need help with my homework please!

    Hint:
    Java Code:
    if ((condition1) || (condition2)) {
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default 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.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Need help with my homework?
    By kurtashug in forum New To Java
    Replies: 10
    Last Post: 03-09-2017, 09:24 AM
  2. Help with Homework
    By smalljynx in forum New To Java
    Replies: 11
    Last Post: 05-27-2015, 10:30 AM
  3. Homework Help please!
    By ghjk in forum New To Java
    Replies: 5
    Last Post: 03-19-2012, 02:44 AM
  4. Please Help with Homework
    By theuser in forum Advanced Java
    Replies: 2
    Last Post: 07-30-2009, 03:37 PM
  5. help with homework
    By pinkdiamondgail in forum Advanced Java
    Replies: 7
    Last Post: 04-07-2009, 01:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •