Programming and Problem Solving with Java

(やまだぃちぅ) #1

266


4.Design and write an application that prints out the approximate number of
words in a file of text. For our purposes, this number is the same as the number
of gaps following words. A gapis defined as one or more spaces in a row, so a
sequence of spaces counts as just one gap. The newline character also counts
as a gap. Anything other than a space or newline is considered to be part of a
word. For example, there are 13 words in this sentence, according to our defini-
tion. The application should echo-print the data.
Use meaningful variable names, proper indentation, and appropriate com-
ments. Thoroughly test the application with your own data sets.

Case Study Follow-Up


1.Change the Incomesapplication so that it does the following:
a.Prints an error message when a negative income value is input and then
goes on to process any remaining data. The erroneous data should not be in-
cluded in any of the calculations. Thoroughly test the modified application
with your own data sets.
b.Does not produce infinity values when the input file contains no males or
no females (or the file is empty). Instead, it should print an appropriate error
message. Test the revised application with your own data sets.
c. Rejects data sets that are coded with a letter other than ‘F’ or ‘M’ and prints
an error message before continuing to process the remaining data. The
application also should print a message indicating the number of erroneous
data sets encountered in the file.
Free download pdf