You could make a method in your parameters class called getCalculator, which simply returns the calculator -
public Calculator getCalculator()
{
return calc;
}
Then create an instance of parameters in intake and call the getCalculator method upon it.
Parameters pram = new Parameters();
Calculators calc2 = new Calculators();
calc2 = pram.getCalculator();
Hopefully that will help. :)
MrScruff
Junior Poster in Training
89 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
public Calculator getCalculator()
{
return calc;
}
You never declare what 'calc' is.
public Calculator getCalculator()
{
Calculator calc;
return calc;
}
However I would assume that you would assign something to 'calc'?
jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1
it would have to be the calculator created in parameters so
public Calculator getCalculator()
{
Calculator calc1;
calc1 = calc;
return calc1;
}
hows that? but then if its been declared public at the top you should just be able to return calc. :S what you reckon?
MrScruff
Junior Poster in Training
89 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
I think what you have is an issue of scope.
Looking at the above, I think you placed the getCalculator method in the wrong class. It should go in the Parameters Class.
So you would have the following:
public class Parameters{
Calculations calc = new Calculations();
//some calculations done using variables in the calculations class
//and new data is saved
public Calculations getCalculator() {
return calc;
}
} //end of Parameters.class
public class Intake{
// I now want to work with the instance "calc" created above so I can
// use the variables that were set in Parameters.class, but I don't know
// how to reference this instance!!
Parameters pram = new Parameters();
Calculators calc2 = new Calculators();
calc2 = pram.getCalculator();
}
jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1
Opps, I mispelled, Calculations
The second class should be:
public class Intake{
// I now want to work with the instance "calc" created above so I can
// use the variables that were set in Parameters.class, but I don't know
// how to reference this instance!!
Parameters pram = new Parameters();
Calculations calc2 = new Calculations();
calc2 = pram.getCalculator();
}
Also I suspect you have Calculations defined somewhere?
jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1
Actually you dont even need to assign (I was getting an error too.) This does compile:
public class Intake{
// I now want to work with the instance "calc" created above so I can
// use the variables that were set in Parameters.class, but I don't know
// how to reference this instance!!
Parameters pram = new Parameters();
Calculations calc2 = pram.getCalculator();
// or you could even say (since calc is public)
Calculations calc3 = pram.calc;
}
jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1