Note taking requirement

Instead of traditional notes you should create a document that provides your answers to the activities below. Points:
  • 1 point: at least the first 6 activities completed.
  • 2 points: all activities completed.

Complex Class

For these activities you will be using this Complex class.

Activity 1

Implement a class method, getReal(), that accepts a List<Complex> 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<Complex> interface. The test() method must return true if and only if the imaginary component of the complex number is zero.

Activity 3

Write a class method, getSpecified(), that accepts a List<Complex> and a Predicate<Complex> 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 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.

Activity 9

Write a program that reads all of the Complex numbers (one per line) out of the file complexies.txt and calculates the average angle, in degrees, of all the complex numbers in the file. Hint: Files.lines()