Java Reference
In-Depth Information
PROJECTS INVOLVING BINARY FILES
7.
Write a program that will search a binary file of numbers of type int and write
the largest and the smallest numbers to the screen. The file contains nothing but
numbers of type int written to the file with writeInt .
8.
Write a program that takes its input from a binary file of numbers of type double
and outputs the average of the numbers in the file to the screen. The file contains
nothing but numbers of type double written to the file with writeDouble .
9.
Write a program that takes its input from a binary file of numbers of type
double . The file contains nothing but numbers of type double written to the
file with writeDouble . The program outputs to the screen the average and stan-
dard deviation of the numbers in the file. The standard deviation of a list of
numbers n 1 , n 2 , n 3 , and so forth is defined as the square root of the average of
the following numbers:
( n 1 - a ) 2 , ( n 2 - a ) 2 , ( n 3 - a ) 2 , and so forth.
The number a is the average of the numbers n 1 , n 2 , n 3 , and so forth. Hint:
Write your program so that it first reads the entire file and computes the average
of all the numbers, then closes the file, then reopens the file and computes the
standard deviation. You will find it helpful to first do Programming Project 8
and then modify that program to obtain the program for this project.
10.
Change the definition of the class Person in Display 5.19 to be serializable. Note
that this requires that you also change the class Date . Then write a program to
maintain a binary file of records of people (records of type Person ). Allow com-
mands to delete a record specified by the person's name, to add a record, to
retrieve and display a record, and to obtain all records of people within a speci-
fied age range. To obtain the age of a person, you need the current date. Your
program will ask the user for the current date when the program begins. You can
do this with random access files, but for this exercise do not use random access
files. Use a file or files that record records with the method writeObject of the
class ObjectOutputStream .
Search WWH ::




Custom Search