Board index » jbuilder » using results of a return statement in another method in the class

using results of a return statement in another method in the class


2004-05-24 10:53:34 PM
jbuilder19
Hi
Have been struggling with this for a few days now and I understand you can access the result of a return statement as long as it is in the same class or a public method - so that other classes which inherit that class can use the results - does that sound right?
Anyway in my Superclass I have the following tow methods, but the second will not compile due to the NumDays:
<pre>
// Method to increment the Number of Days an account has been opened for
public int NumDays(BufferedReader In) {
int Result;
System.out.print("\nIncrement Days to ==>");
Result = Text.ReadInt(In);
return(Result);
</pre>
<pre>
// Method to Calculate the interest
public boolean Calc_Interest() {
if (NumDays / 30>= 1)
return(CalcInterest);
}
</pre>
<p>
The compile error I get is:
C:\03032529\term3\8784\assign1\Account.java:60: cannot resolve symbol
symbol : variable NumDays
location: class Account
if (NumDays / 30>= 1)
^
1 error
Tool completed with exit code 1
<p>
can anyone enlighten me on this?
<p>
The idea behind the CalcInterst is that in my other classes, which will inherit these methods from this class, will only run a sum to calculate the interest is CalcInterest is set - meaning they have had an account for 30 days or more.
Having said that I only wanted it to return true if the division comes out with an integer and not a double or float - as it should be calculated every 30 days - will have another think about this part of it, but in the mean time any advise would be great!
<p>
I have looked at the Java tutorial and also several books I have - will continue looking, but appreciate any helpful response to this.
Thanks!
Sonia
 
 

Re:using results of a return statement in another method in the class

You are trying to use NumDays as if if was a variable.
It is a function with a parameter. NumDays(BurreredReader in).
So you need to call like
if (NumDays(inReader) /30>= 1)
where inReader is the bufferedReader that you are using.
KC
sonia wrote:
Quote
Hi

Have been struggling with this for a few days now and I understand you can access the result of a return statement as long as it is in the same class or a public method - so that other classes which inherit that class can use the results - does that sound right?
Anyway in my Superclass I have the following tow methods, but the second will not compile due to the NumDays:

<pre>

// Method to increment the Number of Days an account has been opened for
public int NumDays(BufferedReader In) {
int Result;
System.out.print("\nIncrement Days to ==>");
Result = Text.ReadInt(In);
return(Result);
</pre>
<pre>
// Method to Calculate the interest
public boolean Calc_Interest() {
if (NumDays / 30>= 1)
return(CalcInterest);
}
</pre>
<p>
The compile error I get is:
C:\03032529\term3\8784\assign1\Account.java:60: cannot resolve symbol
symbol : variable NumDays
location: class Account
if (NumDays / 30>= 1)
^
1 error

Tool completed with exit code 1
<p>
can anyone enlighten me on this?
<p>
The idea behind the CalcInterst is that in my other classes, which will inherit these methods from this class, will only run a sum to calculate the interest is CalcInterest is set - meaning they have had an account for 30 days or more.
Having said that I only wanted it to return true if the division comes out with an integer and not a double or float - as it should be calculated every 30 days - will have another think about this part of it, but in the mean time any advise would be great!
<p>
I have looked at the Java tutorial and also several books I have - will continue looking, but appreciate any helpful response to this.
Thanks!
Sonia