I'm working on the following question:
Write a method runningTotal that returns a new ArrayIntList that contains a running total of the original list. In other words, the i th value in the new list should store the sum of elements 0 through i of the original list.
I'm stuck in the last part of second method(return). The method which doesn't have a parameter.
public class ArrayIntList {
private int[] elementData;
private int size;
}
// when client calls : test = ArrayIntList.runningTotal(test);
// the folowing method works fine
public static ArrayIntList runningTotal(ArrayIntList other) {
other.elementData[0] = other.elementData[0];
for(int i = 1; i < other.size; i++){
other.elementData[i] = other.elementData[i]+ other.elementData[i-1];
}
return other;
}
// when client calls: test = test.runningTotal();
public ArrayIntList runningTotal() {
elementData[0] = elementData[0];
for(int i = 1; i < size; i++){
elementData[i] = elementData[i]+ elementData[i-1];
}
return ??;
}