Write a program that searches a file of numbers and displays the largest number, the smallest number, and the average of all the numbers in the file. Do not assume that the numbers in the file are in any special order. Your program should obtain the file name from the user. Use either a text file or a binary file. For the text-file version, assume one number per line. For the binary-file version, use numbers of type double that are written using writeDouble.
This project is deceptive: it requires more programs than the ones listed in the problem definition to process binary and text files containing floating point numbers; additional programs are required to create and view the data files. The solution shown here has separate programs to create and view data files, one for text and another for binary files. The program to process text files requires a method to translate the numbers from a String to type double. The easiest way is to use the wrapper class Double’s parseDouble method.
1) Develop the class to create and view binary data files. Good models to follow are Doubler, Listing 10.8, for the overall program organization, and BinaryOutputDemo, Listing 10.5, for showing the file contents.
2) Develop the class to process the data in a binary file (display the high, low and average), again using Doubler, Listing 10.8, as the model.
Use the programs from these two steps to develop similar programs for text files, but use TextFileOutputDemo, Listing 10.1, and TextFileInputDemo, Listing 10.2, as models for writing to and reading from text files.
See the code in WriteRealNumberBinaryFile.java, RealNumberHighLowAverageBinary.java, WriteRealNumberTextFile.java, and RealNumberHighLowAverageText.java.
You might also like to view...
A _____ is a credit card issued to selected employees to streamline the traditional purchase order and invoice payment processes.
A. procurement card B. smart card C. meta card D. charge card
You can fill a path with a ____ and outline it with a line.
A. color B. pattern C. gradient D. any of the above
When performing a sequential search, we assume all list elements are equally likely to be the target.
Answer the following statement true (T) or false (F)
Which of the following is not a correct way to initialize a built-in array?
a. int n[5]{0, 7, 0, 3, 8, 2}; b. int n[]{0, 7, 0, 3, 8, 2}; c. int n[5]{7}; d. int n[5]{9, 1, 9};