Hello,
Not sure if this is either too easy or just impossible. Here's the story: I'm processing data from a sensor and I have several methods that do a specific task with those input values.
The actual code is a bit long so there's no need to have you read it all. I wrote something simpler with the basic idea of what I'm trying to do. I'll try to explain it first:
Let's say I have 5 void methods: A, B, C, D and main ("main" is not really the problem here though).
1. Method "A" passes a variable (int data) to method "B"
2. Method "B" does something with that variable.
3. Method "A" also passes the variable "data" to method "C".
4. Now, method "B" and method "C" want to pass the processed data (two variables = one variable from each method) to one more method called "D", which will give me a final result.
So basically, method "D" is taking a variable from both method "B" and "C". I've been trying to do that but I get an error in method "B" and "C" saying that method "D" requires two variables, not one. It's obvious, I'm giving it only one variable per method but method "D" needs two arguments. I hope you're still reading this and sorry if I made it complicated, please check the code below, very simple:
package passing; public class Passing { Passing p; public static void main(String[] args) { new Passing().sum(); } public void sum() { int x = 3; int y = 7; int mySum1 = x + y; int mySum2 = 2 * x + y; mult(mySum1, mySum2); add5(mySum1, mySum2); } public void mult(int pass1, int pass2) { int myMult1 = pass1 * pass2; int myMult2 = myMult1 * myMult1; total(myMult1, myMult2); } public void add5(int a, int b) { int add = a + b + 5; total(add); } public void total(int r1, int r2, int r3) { System.out.println(r1+ "\t"+ r2); } }
Any help on this will be much appreciated, thanks.