Java Reference
In-Depth Information
3.
Write a program that takes its input from a text file of strings representing num-
bers of type double and outputs the average of the numbers in the file to the
screen. The file contains nothing but strings representing numbers of type
double , one per line.
4.
Write a program that takes its input from a text file of strings representing num-
bers of type double . The program outputs to the screen the average and standard
deviation of the numbers in the file. The file contains nothing but strings repre-
senting numbers of type double , one per line. 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 3
and then modify that program to obtain the program for this project.
5.
Write a program to edit text files for extra blanks. The program will replace any
string of two or more blanks with a single blank. Your program should work as
follows: Create a temporary file. Copy from the file to the temporary file but do
not copy extra blanks. Copy the contents of the temporary file back into the
original file. Use a method (or methods) in the class File to remove the tempo-
rary file. You will also want to use the class File for other things in your pro-
gram. The temporary file should have a name different from all existing files so
that the existing files are not affected (except for the file being edited). Your pro-
gram will ask the user for the name of the file to be edited. However, it will not
ask the user for the name of the temporary file but instead will generate the name
within the program. You can generate the name any way that is clear and effi-
cient. One possible way to generate the temporary file is to start with an unlikely
name, such as "TempX" , and to append a character, such as 'X' , until a name is
found that does not name an existing file.
6.
Write a program that gives and takes advice on program writing. The program
starts by writing a piece of advice to the screen and asking the user to type in a
different piece of advice. The program then ends. The next person to run the
program receives the advice given by the person who last ran the program. The
advice is kept in a text file and the content of the file changes after each run of
the program. You can use your editor to enter the initial piece of advice in the
file so that the first person who runs the program receives some advice. Allow the
user to type in advice of any length so that it can be any number of lines long.
The user is told to end his or her advice by pressing the Return key two times.
Your program can then test to see that it has reached the end of the input by
checking to see when it reads two consecutive occurrences of the character '\n' .
Search WWH ::




Custom Search