Question: java code level: beginner write a method about recursion do not write any helper method. findAverage() public static double findAverage(ArrayList list) This method returns the

java code

level: beginner

write a method about recursion do not write any helper method.

findAverage()

public static double findAverage(ArrayList list)

This method returns the average value in the given ArrayList.

For example, if ArrayList list is {1, 2, 3, 4}, findAverage(list) will return 2.5.

  • Return null if the list is empty or null.
  • Think about base case.
    • When should the method terminate/end?
    • Under what condition should your method stop making recursive calls and return your expected value?
  • Think about the recursive case
    • Make recursive calls to the method; make sure to make a function call to findAverage
    • How would the input have to change in the recursive call?
  • You do not need to keep the original content of the list.
  • An iterative solution will not be accepted; do NOT use a for loop.
  • Hint: You should use the idea you used in sumList because finding the average requires calculating the sum.
    • However, you cannot use sumList in this method directly. You are only allowed to make function calls to findAverage itself.
    • You cannot call the method sumList in findAverage
    • What operation do you have to do on the sum to find the average?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!