File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Passing parameters to functions help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Passing parameters to functions help. " Watch "Passing parameters to functions help. " New topic
Author

Passing parameters to functions help.

D Lee
Greenhorn

Joined: May 17, 2006
Posts: 4
Hello all.
I will try to explain this in as much detail as I can. well here goes.
I am trying to pass "NUMDAYS" as well as the Array "swell_height" to al lthe functions.
but here is the problem, no matter what () i put "swell_hieght,NUMDAYS" into i get all sorts of random erros that range from:
"identifier expected"
" ')' expected"
"loadswell() in SwellHeightsRedone cannot be applied to (int) "

now, to solve this problem I CANNOT USE GLOBAL VARIABLES, and i need to find out where and how to pass the variables.

so thanks in advance.

heres the code:

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
In order to send values to a method, you need to create a formal parameter list.

This is a list consisting of 0 or more declarations of the form

type formalparametername

If you have more than 1 parameter, you seperate the list by commas.

In order to call the method, you have to form the call and send an actual parameter list that matches each formal parameter in type and position.
D Lee
Greenhorn

Joined: May 17, 2006
Posts: 4
I thought so BUT when I type in the code:

//If a in input form user it runs this section
case 'a' :
loadswell(Array swell_height, int NUMDAYS);
break;
case 'b' :
dipswell();
break;
default :


I get all sorts of errors
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
That's because you don't have a version of loadswell that has a formal parameter list that matches in type and position the variables you try to send to the method.

Also when you call a method, you do not include the type of the parameters.
[ May 18, 2006: Message edited by: Keith Lynn ]
D Lee
Greenhorn

Joined: May 17, 2006
Posts: 4
I dont know what that is tat you are talking about?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

You are missing something very basic here: how to write methods that take arguments.

Look at this tutorial, especially at "Calling an Object's Methods": Learning the Java Language - Using Objects

You need to create a method called loadswell that takes parameters. The method will look something like this:

And then you call it by passing it some variables between parentheses. Note, you do not specify the types in the call:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
D Lee
Greenhorn

Joined: May 17, 2006
Posts: 4
ahhh thanks man, i knew it was something small like that, but i could not for the life of me remember what had to be done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing parameters to functions help.
 
Similar Threads
Problem with Loop
Stuck on a question
Exceptions problem
How would i break this down into seperate metods?
Multi dimensional arrays