pass on value
PlaneTeeR
Posts: 100
how can i pass on the value between the classes, this is what i used:
I wanted the processor to calculate the speed with calculateSpeed() and give it to display with getSpeed().
In display i placed a system print line but it didn't print, what should i do? or what did i do wrong?
Johnny
I wanted the processor to calculate the speed with calculateSpeed() and give it to display with getSpeed().
In display i placed a system print line but it didn't print, what should i do? or what did i do wrong?
Johnny
Comments
as arguments to methods, but then only those methods know the value
or as arguments to constructors, that store it locally.
The stored value is then known to all the methods of that class.
For example in classI:
classII myClassII = new classII(someValue); //pass someValue to classII
In classII:
public class classII {
· int value;
· //constructor
· public classII(int value) {
··· this.value = value; //store the passed value
· }
· public void someMethod(int value) {
··· return this.value + value; //some calculation with the stored value and the value argument
· }
}
In case of identical names, use the this. prefix to access the locally stored class variables.
regards peter
Post Edited (Peter Verkaik) : 5/30/2006 8:44:05 PM GMT
Processor:
...
sen = new Sensor();
...
public void calculateSpeed(){
· spd = UnsignedIntMath.umulf((short)36000,UnsignedIntMath.ufrac(circumference,sen.getPulseTime()));
}
Sensor:
· private int pulseTime;
· public int getPulseTime() {
··· return pulseTime;
· }
It must work?
regards peter