There is a more recent offering of this course. This is an archive of the
course which was offered in Winter 2017-2018.
Week
9
Class Activity
Week 9 in class activity
Functional Programming
## Complex Class
For these activities you will be using this [__`Complex`__](Complex.java) class.
## Activity 1
Implement a method, `getReal()`, that accepts a `List` and returns a list of all the complex numbers where the imaginary component is zero.
## Activity 2
Write a class, `IsReal`, that implements the [`Predicate`](https://docs.oracle.com/javase/8/docs/api/java/util/function/Predicate.html) interface. The `test()` method must return `true` if and only if the imaginary component of the complex number is zero.
## Activity 3
Write a method, `getSpecified()`, that accepts a `List` and a `Predicate` and returns a list of all the complex numbers for which the predicate is true.
## Activity 4
Write a code snippet that calls `getSpecified()` using an `IsReal` object. Then rewrite the call using a lambda expression instead of an `IsReal` object.
## Activity 5
Write a code snippet that calls `getSpecified()` using a lambda expression that produces true whenever the magnitude of the complex number is greater than 27 for the predicate.
## Activity 6
Make use of a [`Stream`](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html) to generate the same list as required by the previous problem. You may not use `getSpecified()`. Instead you should use `Stream.filter()` and `Stream.collect()`.
## Activity 7
Use the `List.forEach()` method to display each complex number on a separate line.
## Activity 8
Make use of a `Stream` and `DoubleStream` to calculate the average angle, in degrees, of the complex numbers in a list.