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.
Step by Step Answer:
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp