Object oriented programming: Method Capabilities

I'm sorry for, maybe, repeating the same question once again, but I'm lost and don't know where to go. After tons of googling and RTFMing everything I can find on methods I still can't find an answer that would satisfy me.

Object oriented programming is relatively new to me (with several years of experience with procedural programming), and not one tutorial can describe what exactly methods and classes can do.

For example: I have a method that calculates a bunch of results from 2 long variables; After calculation is done, I want my program to take two other variables, do the same thing with them but write the results in different variables, so I can have the result of first AND second calculation.

What I did: I set up a do while loop with a lot of cases in it. Each case places different variables for calculating and, after calculation, variable for queue does a step so loop will run again through a different case. And this is how I'd write with procedural programming

But there must be a way to do this more elegantly, by using methods. And now, the main question: Can methods output several variables without writing bits of code for sending the result to already declared placeholders? Can you input several variables in your method when you call it? What is the syntax for doing this?

Lastly, can someone give me a pointer on where to find a good java tutorial? Everything I've found either treats me like a child with bicycle examples or full of technical information I don't understand yet.

Jon Skeet
people
quotationmark

For example: I have a method that calculates a bunch of results from 2 long variables

That sounds like you should encapsulate the results in a new class then, and use method parameters for the two inputs. Any time you have multiple related values, that's at least a hint that bundling them together in a class might be a good idea.

After calculation is done, I want my program to take two other variables, do the same thing with them but write the results in different variables, so I can have the result of first AND second calculation.

With the above approach, that just means calling the method again, passing in two different inputs:

CalculationResult result1 = calculateResult(x1, x2);
CalculationResult result2 = calculateResult(y1, y2);

people

See more on this question at Stackoverflow