Java Reference
In-Depth Information
If the strings are not sorted in the file, displays the first two strings that are out
of the order.
**12.22
( Replace text ) Revise Programming Exercise 12.16 to replace a string in a file
with a new string for all files in the specified directory using the command:
java Exercise12_22 dir oldString newString
**12.23
( Process scores in a text file on the Web ) Suppose that the text file on the
Web http://cs.armstrong.edu/liang/data/Scores.txt contains an unspecified number
of scores. Write a program that reads the scores from the file and displays their
total and average. Scores are separated by blanks.
*12.24
( Create large dataset ) Create a data file with 1,000 lines. Each line in the file
consists of a faculty member's first name, last name, rank, and salary. The
faculty member's first name and last name for the i th line are FirstName i and
LastName i . The rank is randomly generated as assistant, associate, and full.
The salary is randomly generated as a number with two digits after the decimal
point. The salary for an assistant professor should be in the range from 50,000
to 80,000, for associate professor from 60,000 to 110,000, and for full professor
from 75,000 to 130,000. Save the file in Salary.txt . Here are some sample data:
FirstName1 LastName1 assistant 60055.95
FirstName2 LastName2 associate 81112.45
. . .
FirstName1000 LastName1000 full 92255.21
*12.25
( Process large dataset ) A university posts its employees' salaries at http://
cs.armstrong.edu/liang/data/Salary.txt . Each line in the file consists of a faculty
member's first name, last name, rank, and salary (see Programming Exercise
12.24). Write a program to display the total salary for assistant professors,
associate professors, full professors, and all faculty, respectively, and display
the average salary for assistant professors, associate professors, full professors,
and all faculty, respectively.
**12.26
( Create a directory ) Write a program that prompts the user to enter a directory
name and creates a directory using the File 's mkdirs method. The program
displays the message “Directory created successfully” if a directory is created
or “Directory already exists” if the directory already exists.
**12.27
( Replace words ) Suppose you have a lot of files in a directory that contain
words Exercise i _ j , where i and j are digits. Write a program that pads a 0
before i if i is a single digit and 0 before j if j is a single digit. For example,
the word Exercise2_1 in a file will be replaced by Exercise02_01 . In Java,
when you pass the symbol * from the command line, it refers to all files in
the directory (see Supplement III.V). Use the following command to run your
program.
java Exercise12_27 *
**12.28
( Rename files ) Suppose you have a lot of files in a directory named Exercise i _ j ,
where i and j are digits. Write a program that pads a 0 before i if i is a single
digit. For example, a file named Exercise2_1 in a directory will be renamed to
Exercise02_1 . In Java, when you pass the symbol * from the command line,
it refers to all files in the directory (see Supplement III.V). Use the following
command to run your program.
java Exercise12_28 *
 
Search WWH ::




Custom Search