Write a method that takes a List of String
and returns a List of Integer containing
the lengths of the strings.
Write a method that takes a List of String
and inserts the String "really" immediately
before any occurrence of "good" or "bad".
Write a method that takes a List of Sale
objects and a String day name and returns a
new List of Sale objects containing only
the Sale objects from that day. It should not modify the
argument List.
Write a method that takes a List of Sale
objects and a String and returns the average units sold for
the given day. To compute the average units sold for a given day, find all
the sales that occurred on that day and count them and total the units
sold and then compute the average.
Write a method that takes a List of Sale objects
and returns the Sale object with the highest value (number of
units times unit price). If there are ties, return the
first Sale with that value.
Write a method that takes a List of Sale objects
and an int target and returns a boolean indicating whether
the total value of any Sale (number of units times unit
price) is greater than the target.
A few more List methods to practice with. Several of the
problem in this set use a class Sale which represents a sale of
some number of a given kind of item at a certain price on a particular day.
The Sale class provides the instance methods String
day(), String item(), int units(),
and int unitPrice() to access the values of
the Sale object.
Declare all your parameters, return types, and variables using the
interface type List, not ArrayList. Since
List is an interface, when you need to make a new list you
will still construct an ArrayList, e.g. List<String>
result = new ArrayList<>();