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.

as i say im trying to determine the actual and formal parameters used in the definition and call of the method, 'test'

any help would be appreciated, thanks very much

what i have at the minute (i have to answer this by reasoning it out)is the following-

'When declaring your method at the top of a piece of code the header determines if a method returns any result or takes any parameters on. A method should either return a value or no value (known as an action method) and it can take 0 or more parameters.
Formal parameters are variables that can be declared in the parameter list of a subprogram specification.'

to be honest im taking a lot of that from the notes my lecturer provided (not directly) so im not so sure what that last bit means.

again any help will be greatly appreciated

cheers

Last edited by javanoobie; December 4th, 2010 at 09:31 AM.
Reason: editing so i dont come across as a lazy sod

The first line of your "test" method (public static void test(int num)) you have told it that an int has to be used for this method.
I am assuming you understand what the if and else statement does, but if not your simply saying, if the number is greater than ten, a new variable called half has to be created. Half must be an int(int half), and half is = to the number entered/2. The System.out.println("Half num = " + half); is telling it what to output.
the else, means that if the number is not greater than ten, output will be whatever number they have entered.

This is where you are testing your method. You are creating an int called x to be passed into( public static void test(int num) ). And you are calling the method here -> test(x);. Because you called you method "test" and in the body of the code you have correctly called it.

I hope this has helped you in some way. Its the best explanation i could come u with. Just to let you know, if int x = 13; or any odd number it will return half of the number below x. As in int x =13; output would be 12.

Re: Actual and formal parameters

Consider a computer program according to this analogy:

Everything that can be done on a computer (well, computationally) can be computed using a pencil and some paper. The code is the instructions which tells the person (computer) what to write/erase/compute on the paper.

So your program will start running on one piece of paper. You can write down variables and values, perform mathematical computations, etc. When you call a method, that's analogous to getting a new piece of paper out, then copying the values of the parameters to that new piece of paper (well, actually either the values or the location of these values is copied, but we won't worry about this for now). The original piece of paper is then set aside, and while you're working on computations for this other method, you can't look at the original piece of paper for variables/values/etc.

Once you've reached the end of the method (or a return statement), you copy the return value if any back to your original piece of paper. Then all the work you did on the piece of paper for that method is crumpled and tossed into the recycling bin (i.e. you can't look at anything on that paper again).

While actual computers do things a little differently, the basic concept is the same.

Actual parameters are what you're passing to the method when you call it. Formal parameters are what the method expects to receive, and it will complain if it doesn't get them.

Re: Actual and formal parameters

thank you both very much, that cleared it up beautifully. Now having finished that question i'm onto the next one which actually involves creating a program, so you can probably imagine how lost i am with that given my above question. I dont want to come across as though im trying to use this as a homework service because im not, i do actually want to learn because il need this stuff in the years to come, but considering the following text:

Design a program that will manage the paper consumed by the University
reprographics department. The program should allow the reprographics manager to
input the current paper stock level and a paper re-order level, followed by a number
of paper transactions.

Each transaction consists of a transaction code (char) and a
transaction amount (int). The transaction code can be ‘A’ to add paper to stock or ‘R’
to remove paper from stock.

The only other valid option is ‘Q’ to quit the program.
Before removing any paper from stock the program should check that there is
sufficient stock and if not the program should simply print “** Insufficient Stock **”
and NOT modify the stock level.

After each transaction the program should print the stock level, followed by “** Reorder
**” IF the stock level is below the re-order level. When there are no more
transactions a ‘Q’ can be entered for the transaction code to signify the end of the
data.

as you can see i need to construct an algorithm, and im even stuck at that, i just cant get my head around the idea despite the good two hours i spent yesterday with my pen and relatively blank paper if someone could even point me in the right direction as regards to a simple algorithm i could use for this i might be able to make a start on coding it myself,

Re: Actual and formal parameters

edit: i just cant decide whether i need to set each thing to the numbers specified or whether to leave them to be entered by the user, and if its the latter i honestly dont even know where to start. my notes only cover the very basics of making an algorithm