Week 7
Class Activity
## Complex Class For these activities you will be using this [__`Complex`__](Complex.java) class. ## Activity 1 Implement a `write(DataOutputStream out)` method in the `Complex` class that will write the fields of the `Complex` object to a binary output stream. ## Activity 2 Implement a `read(DataInputStream in)` method in the `Complex` class that will read a complex number from a binary input stream and return a `Complex` object with the value read from the stream. ## Activity 3 Write a driver program that creates four complex numbers: 1.0 + 0.0i, -2.3 - 5.0i, 0.0 + 3.0i, and 8.0 + 8.0i and writes them to a binary file. ## Activity 4 Write another driver program that reads two complex numbers from a binary file and displays them to the console in both cartesian and polar form. ## Activity 5 Implement a `write(PrintWriter out)` method in the `Complex` class that will write the fields of the `Complex` object to a text output stream. ## Activity 6 Implement a `read(Scanner in)` method in the `Complex` class that will read a complex number from a text input stream and return a `Complex` object with the value read from the stream. ## Activity 7 Write another driver program that creates four complex numbers: 1.0 + 0.0i, -2.3 - 5.0i, 0.0 + 3.0i, and 8.0 + 8.0i and writes them to a text file. All numbers should be on one line and separated by commas. ## Activity 8 Write another driver program that reads all complex numbers in a text file (assume no other data is in the file and that the format described in the previous activity is used) and displays them to the console in cartesian form. ## Activity 9 Modify the `Complex` class so that it can be written to an `ObjectOutputStream`, and write a driver program that creates four complex numbers: 1.0 + 0.0i, -2.3 - 5.0i, 0.0 + 3.0i, and 8.0 + 8.0i and writes them to a binary file as objects. ## Activity 10 Write another driver program that reads four complex numbers that have been written to a binary file as objects, and displays them to the console in polar form.

Friday, 19-Jan-2018 16:42:35 CST