this program is throwing an error, can you help fix cannot find symbol final int
ID: 3763872 • Letter: T
Question
this program is throwing an error, can you help fix
cannot find symbol
final int ldu = Util.ldu( capacity ) + 1;
^
symbol: variable Util
location: class RealSum
1 error
public class RealSum
{protected boolean[] flags;
protected double[] sums;
public RealSum()
{
flags = new boolean[ 1 ];
sums = new double[ 1 ];
}
public RealSum( final int capacity ){
final int ldu = Util.ldu( capacity ) + 1;
flags = new boolean[ ldu ];
sums = new double[ ldu ];
}
final public double getSum()
{
double sum = 0;
for ( final double s : sums )
sum += s;
return sum;
}
final protected void expand( final double s )
{
final double[] oldSums = sums;
sums = new double[ oldSums.length + 1 ];
System.arraycopy( oldSums, 0, sums, 0, oldSums.length );
sums[ oldSums.length ] = s;
final boolean[] oldFlags = flags;
flags = new boolean[ sums.length ];
System.arraycopy( oldFlags, 0, flags, 0, oldFlags.length );
flags[ oldSums.length ] = true;
}
final public void add( final double a )
{
int i = 0;
double s = a;
try{
while ( flags[ i ] )
{
flags[ i ] = false;
s += sums[ i ];
sums[ i ] = 0.0;
++i;
}
flags[ i ] = true;
sums[ i ] = s;
return;
}
catch ( final IndexOutOfBoundsException e )
{
expand( s );
}
}
}
Explanation / Answer
Pl. make this correction in your program:
final int ldu = capacity + 1;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.