4 Replies - 1394 Views - Last Post: 06 October 2013 - 10:44 AM Rate Topic: -----

#1 coxxie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 11

Geometry: Display angles of a triangle

Posted 05 October 2013 - 11:02 AM

(Geometry: display angles) Write a program that prompts the user to enter three
points of a triangle and displays the angles in degrees. Round the value to keep
two digits after the decimal point. The formula to compute angles A, B, and C are
as follows:

A = arccos((a * a - b * b - c * c) / (-2 * b * c))
B = arccos((b * b - a * a - c * c) / (-2 * a * c))
C = arccos((c * c - b * b - a * a) / (-2 * a * B)/>/>)

Here is a sample run of the program:

Enter three points: 6.5 6.5 2.5
The three angles are 15.26 90.0 74.74

Here is my code so far: I am having trouble trying to take in three variables, pass them to the method and then return them.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg5.pkg23;

/**
 *
 * @author Coxxie
 */
import java.util.Scanner;
        
public class Main
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter 3 sides of a triangle: \n");
        System.out.print("Enter side A of a triangle: \n");
        double sideA = input.nextInt();
        System.out.print("Enter side B of a triangle: \n");
        double sideB = input.nextInt();
        System.out.print("Enter side C of a triangle: \n");
        double sideC = input.nextInt();
        
        double anglel = angleA(sideA, sideB, sideC);
        double angle2 = angleB(sideA, sideB, sideC);
        double angle3 = angleC(sideA, sideB, sideC);
        
        System.out.println
                ("The three angles are: " + angleA(anglel) + " "+ angleB(angle2) + " " + angleC(angle3));
      
    }
    
    public static double angleA(double sideA, double sideB, double sideC)
    {
        //figA = equation in book. Imput it in and copy in sides.
       double angA = Math.acos((sideA * sideA - sideB * sideB - sideC * sideC) / (-2 * sideB * sideC));  
                
       return angA; 
    }
    
   public static double angleB(double sideA, double sideB, double sideC)
    {
        //figA = equation in book. Imput it in and copy in sides.
       double angB = Math.acos((sideA * sideA - sideB * sideB - sideC * sideC) / (-2 * sideB * sideC));  
                
       return angB; 
    }
    
    public static double angleC(double sideA, double sideB, double sideC)
    {
        //figA = equation in book. Imput it in and copy in sides.
       double angC = Math.acos((sideA * sideA - sideB * sideB - sideC * sideC) / (-2 * sideB * sideC));  
                
       return angC; 
    }
}

This post has been edited by jon.kiparsky: 05 October 2013 - 11:15 AM
Reason for edit:: [code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: Geometry: Display angles of a triangle

#2 Mylo  Icon User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

Re: Geometry: Display angles of a triangle

Posted 05 October 2013 - 11:32 AM

Why are you making your code about sides? Aren't you supposed to be entering points?

Quote

I am having trouble trying to take in three variables, pass them to the method and then return them.

You seem to have done all of these already. Apart from here:
 System.out.println("The three angles are: " + angleA(anglel) + " "+ angleB(angle2) + " " + angleC(angle3));

in which case, this is what was probably intended:
 System.out.println("The three angles are: " + anglel + " "+ angle2 + " " + angle3);

Don't forget to convert your answers to degrees.

This post has been edited by Mylo: 05 October 2013 - 11:43 AM

Was This Post Helpful? 1
  • +
  • -

#3 schutzzz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 136
  • View blog
  • Posts: 338
  • Joined: 22-April 13

Re: Geometry: Display angles of a triangle

Posted 05 October 2013 - 12:43 PM

Your methods angleA, angleB, and angleC each require 3 parameters. You're only giving them each one.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Geometry: Display angles of a triangle

Posted 05 October 2013 - 06:04 PM

why 3 methods angleA(), angleB() and angleC() that do exactly the same thing ?
You need only one named angle()
Was This Post Helpful? 0
  • +
  • -

#5 coxxie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 11

Re: Geometry: Display angles of a triangle

Posted 06 October 2013 - 10:44 AM

I was focusing to much on the diagram provided for the and didn't read the problem though all the way. I was focusing on sides and not points of the triangle. When I get my code updated I will up load it.

Thanks for the pointers so far.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1