# [BEGINNER] Calling a function with multiple arguments

• 11-07-2013, 10:10 PM
trilla
[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.

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!
• 11-07-2013, 10:16 PM
Norm
Re: [BEGINNER] Calling a function with multiple arguments
Quote:

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

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)
• 11-07-2013, 10:36 PM
trilla
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....
• 11-07-2013, 10:54 PM
Norm
Re: [BEGINNER] Calling a function with multiple arguments
It's explained in the tutorial. And there are examples.
• 11-07-2013, 11:01 PM
trilla
Re: [BEGINNER] Calling a function with multiple arguments
So is my:
public void GreatCircle(String[] args) {

Totally useless or unusable in this context?
• 11-07-2013, 11:15 PM
Norm
Re: [BEGINNER] Calling a function with multiple arguments
Quote:

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.
• 11-07-2013, 11:24 PM
trilla
Re: [BEGINNER] Calling a function with multiple arguments
Quote:

Originally Posted by Norm
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?
• 11-07-2013, 11:35 PM
Norm
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...
• 11-07-2013, 11:48 PM
trilla
Re: [BEGINNER] Calling a function with multiple arguments
Quote:

Originally Posted by Norm
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...

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.
• 11-08-2013, 12:00 AM
Norm
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)
• 11-08-2013, 12:56 AM
trilla
Re: [BEGINNER] Calling a function with multiple arguments
Quote:

Originally Posted by Norm
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................
• 11-08-2013, 02:11 AM
Junky
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!
• 11-08-2013, 02:12 AM
Norm
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.
• 11-08-2013, 06:04 AM
trilla
Re: [BEGINNER] Calling a function with multiple arguments
Quote:

Originally Posted by Norm
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.
• 11-08-2013, 09:03 AM
JosAH
Re: [BEGINNER] Calling a function with multiple arguments
Quote:

Originally Posted by trilla
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
• 11-08-2013, 10:34 AM
gimbal2
Re: [BEGINNER] Calling a function with multiple arguments
Quote:

Originally Posted by trilla
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.