DataSet.java
/**
Computes the sum of a set of data values.
*/
public class DataSet
{
private int[] values;
private int first;
private int last;
/**
Constructs a DataSet object.
@param values the data values
@param first the first value in the data set
@param last the last value in the data set
*/
public DataSet(int[] values, int first, int last)
{
this.values = values;
this.first = first;
this.last = last;
}
/**
Gets the sum in the set of data values
@return the sum value in the set
*/
public int getSum()
{
. . .
}
}
Use the following file:
DataSetTester.java
import java.util.Random;
/**
A tester class for the recursive sum.
*/
public class DataSetTester
{
public static void main(String[] args)
{
final int LENGTH = 10;
int[] values = new int[LENGTH];
for (int i = 0; i < values.length; i++)
{
values[i] = i - 5;
}
DataSet d = new DataSet(values, 0, values.length - 1);
System.out.println("Sum: " + d.getSum());
System.out.println("Expected: -5");
}
}