Lab 08 - Generics and Streams

Instructions

For each problem, create a class named ProblemX, where X is the problem number (e.g., Problem1.java). Write corresponding JUnit test classes named ProblemXTest. All methods (yes, including helpers) must include proper Javadoc comments describing the (1) purpose of the method, (2) parameters, and (3) return value. Helper methods should be marked as private. You do not need to write explicit tests for helper methods because they will be indirectly tested through the driver methods.

For problems containing multiple parts, write the methods inside the same class.

What You Cannot Use

You may not use anything beyond Chapter 3. This includes but is not limited to:

Any violation results in a score of 0 on the lab.

Please contact a staff member if you are unsure as to whether you're allowed to use something.

Notes and Version Changes:

Problems

  1. (30 points) Design the List<Integer> remvDups(List<Integer> lon) method, which receives a list of integers and removes all duplicate integers. Return this result as a new list. You must use only the Stream API.

    Files to Submit: Problem1.java, Problem1Test.java

  2. (30 points) Design the List<Double> filterThenSquare(List<Double> lon) method, which receives a list of doubles, removes all numbers that are multiples of seven, and squares the remaining values. Return this result as a new list. You must use only the Stream API.

    Files to Submit: Problem2.java, Problem2Test.java

  3. (40 points) Design the Optional<Integer> maximum(List<Integer> lon) method that, when given a list of integers, returns the maximum value in the list as an Optional<Integer>. If there are no values in the given list, return Optional.empty(). You must use only the Stream API.

    Note: With this problem, don't cheese it by calling the IntStream max method. Figure out how to solve it with reduce or collect! As a hint, think about how you would find the maximum number in a list of numbers using recursion.

    Hint: There are two versions of reduce that you can call...

    Files to Submit: Problem3.java, Problem3Test.java