Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: User-Defined Methods

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


    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);
         }
     
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: User-Defined Methods

    String s = "hello world";
    System.out.println(String s);
    What is wrong with the above code?
    Improving the world one idiot at a time!

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: User-Defined Methods

    Once you solve that riddle you have numerous other problems with your code.
    Improving the world one idiot at a time!

  4. #4
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: User-Defined Methods

    Quote Originally Posted by Junky View Post
    String s = "hello world";
    System.out.println(String s);
    What is wrong with the above code?
    System.out.println(s);

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default 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.
    Improving the world one idiot at a time!

Similar Threads

  1. Replies: 0
    Last Post: January 25th, 2011, 01:24 AM
  2. I need help with METHODS!!!
    By Slone in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 14th, 2010, 08:33 AM
  3. methods help
    By hockey87 in forum AWT / Java Swing
    Replies: 1
    Last Post: March 9th, 2010, 11:57 PM
  4. Re-using methods?
    By Morevan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2010, 05:04 PM
  5. User Defined Methods
    By mgutierrez19 in forum Object Oriented Programming
    Replies: 11
    Last Post: October 20th, 2009, 06:57 PM