i have done this so far, but having difficulty with part b. It is a mock exam paper and not sure on the rest of part b.
Q)
Sum up the elements of a sequence given by s.valAtIndex(i)
.
s is of type Seq.
Seq is an interface that has a method valAtIndex (integer parameter and double result)
.
(a) write the interface Seq.
(b) write a class Geometric, implementing Seq. so that each instance s represents a geometric series as follows
s.valAtIndex(0), s.valAtIndex(0)
...
such that the ith element s.valAtIndex(i)
is equal to the ith power of the base b i.e. b^i. (recall that b^0=1)
(a)
public interface Seq{
public double valAtIndex(int i);
}
(b)
public Geometric implements Seq{
Seq s;
private double b;
public Geometric(double a){
s = new Geometric(a);
this.b=a;
}
@Override
public double valAtIndex(int i){
return 0;//not sure how to do this method
}