User-Defined Methods

• July 26th, 2011, 12:13 AM
ZippyShannon
User-Defined Methods
I am writing a program for my Java class that takes the length of two sides of a right triangle, and calculates the hypotenuse, as well as the sine, cosine, and tangent of each non-right angle of the right triangle. The calculations for the hypotenuse, sine, cosine, and tangent should be placed in separate methods.
I keep getting two errors when I try to declare my methods, 'class' expected and ')' expected. I cannot figure out what I am doing wrong, any help would be appreciated.

Code Java:

```import java.util.*; import static java.lang.Math.*;   public class RightTriangle {   public static void main(String[] args) {   double a, b, c;   System.out.println("Please enter first length" + " of side of the triangle", a); a = console.nextDouble(); System.out.println("The opposite side of the" + "triangle is ", a);   System.out.println("Please enter second length" + " of side of the triangle", b); b = console.nextDouble(); System.out.println("The adjacent side of the" + "trianlge is ", b);   c =((a*a) + (b*b)); hypotenuse = c*c; System.out.println("The hypotenuse of the triangle" + "is ", hypotenuse);   sine(double a, double c);   cosine(double b, double c);   tangent(double b, double c);   }   public static double getSine(double a, double c) { double opp; double hyp;   opp = a.getNum(); hyp = c.getNum();   sine = opp/hyp; System.out.println("The sine of the triangle" + "is ", sine); }   public static double getCosine(double b, double c) { double adj; double hyp;   adj = b.getNum();   hyp = c.getNum();   cosine = adj/hyp; System.out.println("The cosine of the triangle" + "is ", cosine); }   public static double getTangent(double a, double b) { double opp; double adj;   opp = a.getNum(); adj = b.getNum();   tangent = a/b; System.out.println("The tangent of the triangle" + "is ", tangent); }   }```
• July 26th, 2011, 12:28 AM
Junky
Re: User-Defined Methods
Code java:

```String s = "hello world"; System.out.println(String s);```
What is wrong with the above code?
• July 26th, 2011, 12:30 AM
Junky
Re: User-Defined Methods
Once you solve that riddle you have numerous other problems with your code.
• July 28th, 2011, 11:02 PM
hello_world
Re: User-Defined Methods
Quote:

Originally Posted by Junky
Code java:

```String s = "hello world"; System.out.println(String s);```
What is wrong with the above code?

System.out.println(s);
• July 28th, 2011, 11:23 PM
Junky
Re: User-Defined Methods
Congratulations but the question was aimed at ZippyShannon so they can work out for themselves what is wrong with their code.