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
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.
Step by Step Solution
3.46 Rating (178 Votes )
There are 3 Steps involved in it
public ArrayIntList runningTotal ArrayIntList result new ArrayIntList elementDatalength if si... View full answer
Get step-by-step solutions from verified subject matter experts
