Java - calculating the sum of a series of numbers
<p>i am trying to calculate the sum of the first 16 elements of the series 1, 3, 9, 27, 81.... The code does so by first CREATING a suitable instance of Geometric that will be of TYPE Seq.</p>

<pre><code>public class Geometric implements Seq {

private double b;
public Seq s;
public double sum;

public Geometric(double a) {

    this.b = a;
}


public double valAtIndex(int i) {
    // TODO Auto-generated method stub
    return Math.pow(b, i);
}

public double total() {

    s = new Geometric(3.0);
    for (int a = 0; a &lt; 16; a++) {

        int c = -1;
        sum = sum + s.valAtIndex(c = c + 1);
        c++;

    }
    return sum;
}

public double getSum() {

    return sum;
}

public static void main(String[] args) {

    System.out.println(sum);
}
</code></pre>

<p>}</p>

<p>Not sure if i am doing this the long way round? It isnt working yet, eclipse is saying i need to change the modifier of sum to static?</p>
