Coding Exercises: ArrayList
These exercises are the same as the exercises for Arrays. Your goal is to become familiar with the syntax and usage differences between arrays and ArrayLists.
Make sure to write full unit tests for these functions.
1. Count lucky
A number is lucky if it is a multiple of 7 or ends in 7. Write a function that counts the number of lucky numbers in an ArrayList of integers.
countLucky(ArrayList{1, 2, 3}) -> 0
countLucky(ArrayList{7, 13, 17}) -> 2
countLucky(ArrayList{107, 207}) -> 2
2. Sum of squares
Write a function that takes a single ArrayList of doubles as input, and returns the sum of squares of the values.
sumOfSquares(ArrayList{0}) -> 0
sumOfSquares(ArrayList{1.0, 2.0, 3.0}) -> 14.0
sumOfSquares(ArrayList{2.0, 2.0, 2.0}) -> 12.0
3. Total Z name length
Write a function that takes an ArrayList of strings as input, and returns the total length of the strings that start with āzā or āZā.
countZNames(ArrayList{"Dr. Kessner", "Dr. Sands"}) -> 0
countZNames(ArrayList{"Zorro", "zero", "zippy"}) -> 14