There is a more recent offering of this course. This is an archive of the
course which was offered in Winter 2016-2017.
Week
7
Class Activity
Week 7 in class activity
File Input/Output
## 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.