Results 1 to 16 of 16
  1. #1
    trilla is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Question [BEGINNER] Calling a function with multiple arguments

    So for this assignment I'm asked to create a function called 'GreatCircle' that calculates the distance between two points in kilometers. I need the function to take four arguments that are doubles (x1, x2, y1, y2) that represent the latitude and longitude of these two points. The equation that I included should calculate the distance in kilometers, but I have no idea how to call the function in 'main' to check.

    So my question is:

    How do I call 'GreatCircle' in 'main' so I can provide each degree of latitude and longitude and check my work/formatting.



    Java Code:
    public class UseArgument  {
    
         /**
            *@param args the command line arguments
            */
    
    //QUESTION THREE: (Code)
    
           public void GreatCircle(String[] args)  {
               double x1 = Math.toRadians(Double.parseDouble(args[0]));
               double x2 = Math.toRadians(Double.parseDouble(args[1])); 
               double y1 = Math.toRadians(Double.parseDouble(args[2]));
               double y2 = Math.toRadians(Double.parseDouble(args[3]));
    
               double d = 6371*Math.acos((Math.sin(x1))*(Math.sin(x2))+(Math.cos(x1))*(Math.cos(x2))*(Math.cos(y2-y1)));
               
               System.out.println(d);
               }
          public static void main(String[] args)  {
               //TODO code application logic here
    //QUESTION THREE:(Test)
               }
    I know it's probably a simple solution, but thanks for taking the time to read my question anyway!
    Last edited by trilla; 11-07-2013 at 09:15 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: [BEGINNER] Calling a function with multiple arguments

    take four arguments that are doubles (x1, x2, y1, y2)
    define the method to take 4 doubles. Then call it with 4 double values.

    See the tutorial about methods:
    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    trilla is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: [BEGINNER] Calling a function with multiple arguments

    Does 'GreatCircle' not take 4 doubles? Like I said in my initial post, I have no idea how to format this code to "call" 'GreatCircle' to where I can include the 4 values. I know it has to be done in 'main', I just dont know how. Like at all....

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: [BEGINNER] Calling a function with multiple arguments

    It's explained in the tutorial. And there are examples.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    trilla is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: [BEGINNER] Calling a function with multiple arguments

    So is my:
    public void GreatCircle(String[] args) {
    double x1 = Math.toRadians(Double.parseDouble(args[0]));
    double x2 = Math.toRadians(Double.parseDouble(args[1]));
    double y1 = Math.toRadians(Double.parseDouble(args[2]));
    double y2 = Math.toRadians(Double.parseDouble(args[3]));

    Totally useless or unusable in this context?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: [BEGINNER] Calling a function with multiple arguments

    function to take four arguments that are doubles
    Yes, that is not what the requirements were for the method.
    Your version has one String array for its arg
    The requirements were 4 double.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    trilla is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: [BEGINNER] Calling a function with multiple arguments

    Quote Originally Posted by Norm View Post
    Yes, that is not what the requirements were for the method.
    Your version has one String array for its arg
    The requirements were 4 double.
    The assignment explicitly states that the 'GreatCircle' function should print 'd' and not have a return value. My inputs are all degree values as well so I have to find some way to utilize Math.toRadian. Should this be in 'GreatCircle' or 'main' when I input my values?

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: [BEGINNER] Calling a function with multiple arguments

    If the values are to be passed to the method, then I'd guess that they should be read by code in the method that is going to call the other method. If main() calls great.. then main() should read the input and pass it to great...
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    trilla is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: [BEGINNER] Calling a function with multiple arguments

    Quote Originally Posted by Norm View Post
    If the values are to be passed to the method, then I'd guess that they should be read by code in the method that is going to call the other method. If main() calls great.. then main() should read the input and pass it to great...
    I didnt want this to turn into 20 questions but you keep refusing to answer me within the context of my code...

    Java Code:
    //QUESTION THREE:(Code)
         public void GreatCircle(double x1, double x2, double y1, double y2){
             double d = 6731*Math.acos((Math.sin(x1))*(Math.sin(x2))+(Math.cos(x1))*(Math.cos(x2))*(Math.cos(y2-y1)));
             System.out.println(d);
         }
        
         public static void main(String[] args) {
            // TODO code application logic here
    //QUESTION THREE: (Test)
         GreatCircle(double 48.87, double 37.80, double -2.33, double 122.40);
    The function call doesn't work obviously because, as I stated in my initial post, I have no idea how to format the function call with multiple arguments. Understand that I'm a [BEGINNER] and a lot of the tutorial information is making this seem more convoluted and difficult than it is in actuality.
    Last edited by trilla; 11-07-2013 at 10:57 PM.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: [BEGINNER] Calling a function with multiple arguments

    When you get error messages, you need to copy the full text of the messages and paste it here.

    The method definition looks close, the calling of the method needs work. See the tutorial on how to call a method:
    Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    trilla is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: [BEGINNER] Calling a function with multiple arguments

    Quote Originally Posted by Norm View Post
    When you get error messages, you need to copy the full text of the messages and paste it here.

    The method definition looks close, the calling of the method needs work. See the tutorial on how to call a method:
    Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    Are you trolling me lol? You're literally answering my questions with the same question. I understand I have to learn this myself, but these inapplicable tutorials aren't helping................

  12. #12
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: [BEGINNER] Calling a function with multiple arguments

    If we just told you how to fix your problem you would not learn and a week from now you would make the same mistake. Often the regulars on forums will ask you a question. The purpose of this is for you to think about it and arrive at the answer yourself. Thus you actually learn something.

    Norm ask you to post the error message. This means you need to copy and paste the full and exact message here and indicate on which line it occurs. Do this in the future. For now you have a problem when you are trying to call the GreatCircle method. Go back and read notes, textbooks online examples and compare your code to how it should be done. That way you will learn!

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: [BEGINNER] Calling a function with multiple arguments

    What error message do you get? Copy and post the full text.
    Don't expect us to compile your code to find its errors.
    You need to be a little more active in working on this problem. Post everything, don't expect us to do any of the work for you. The more info about your problem you post, the better will be the response. Posting code and then waiting will make for a longer path to finding and fixing the problem.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    trilla is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: [BEGINNER] Calling a function with multiple arguments

    Quote Originally Posted by Norm View Post
    What error message do you get? Copy and post the full text.
    Don't expect us to compile your code to find its errors.
    You need to be a little more active in working on this problem. Post everything, don't expect us to do any of the work for you. The more info about your problem you post, the better will be the response. Posting code and then waiting will make for a longer path to finding and fixing the problem.
    The answer was literally so simple..... but you gave me links to totally inapplicable tutorials that only interfere with what I already know and turn my code into a convoluted mess. What you did totally hindered my ability to learn this.

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default Re: [BEGINNER] Calling a function with multiple arguments

    Quote Originally Posted by trilla View Post
    The answer was literally so simple..... but you gave me links to totally inapplicable tutorials that only interfere with what I already know and turn my code into a convoluted mess. What you did totally hindered my ability to learn this.
    Indeed, the answer is so simple and Norm didn't want to spoonfeed it to you; instead he supplied a link to tutorials that do apply; your mind was blocked and you didn't want to see the light; and maybe you still don't want to see it; until now you and Norm were communicating on different wave lenghts and all Norm could do was either spoofeed you or make you think for yourself. What actually blocked your mind was the conversion of a String representation of the arguments you wanted and the actual method you wanted to implement but didn't know how ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,054
    Rep Power
    6

    Default Re: [BEGINNER] Calling a function with multiple arguments

    Quote Originally Posted by trilla View Post
    What you did totally hindered my ability to learn this.
    Eh no, you do that yourself. Blaming others for your own failure, it is just a crying shame. I'll probably run into you one day when you will serve my hamburger if you keep up this attitude.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Calling a Function
    By skmightymouse in forum New To Java
    Replies: 16
    Last Post: 04-24-2012, 10:39 PM
  2. Calling function in Javascript- from other function
    By jdigger in forum New To Java
    Replies: 1
    Last Post: 02-27-2011, 09:00 PM
  3. Calling the Function again
    By Swetz55 in forum New To Java
    Replies: 2
    Last Post: 12-19-2009, 11:10 AM
  4. Multiple Command Line Arguments
    By turnergirl24 in forum New To Java
    Replies: 4
    Last Post: 12-04-2009, 09:36 PM
  5. Replies: 3
    Last Post: 12-04-2009, 03:08 PM

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
  •