Write a method called runningTotal that returns a new ArrayIntList that contains a running total of the

Question:

Write a method called runningTotal that returns a new ArrayIntList that contains a running total of the original list. In other words, the ith value in the new list should store the sum of elements 0 through i of the original list. For example, given a variable list that stores [2, 3, 5, 4, 7, 15, 20, 7], consider what happens when the following call is made:

ArrayIntList list2 = list.runningTotal();

The variable list2 should store [2, 5, 10, 14, 21, 36, 56, 63]. The original list should not be changed by the method. If the original list is empty, the result should be an empty list. The new list should have the same capacity as the original. Remember that there is a list constructor that accepts a capacity as a parameter.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: