1

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 ??;
}
0

1 Answer 1

5

I think what you need is return this;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.