Java Reference
In-Depth Information
Consider another file data2.txt that exists with the following contents:
This file has a grate deal of
text in it which needs to
bee procesed.
A dialogue with the user running your program might look like the following:
Enter a first file name: data1.txt
Enter a second file name: data2.txt
Differences found:
Line 1:
< This file has a great deal of
> This file has a grate deal of
Line 4:
< be processed.
> bee procesed.
3. Write a program that prompts the user for a file name, assuming that the file contains a Java program. Your program
should read the file and print its contents properly indented. When you see a left-brace character ( { ) in the file,
increase your indentation level by four spaces. When you see a right-brace character ( } ), decrease your indentation
level by four spaces. You may assume that the file has only one opening or closing brace per line, that every block
statement (such as if or for ) uses braces rather than omitting them, and that every relevant occurrence of a { or }
character in the file occurs at the end of a line. Consider using a class constant for the number of spaces to indent (4),
so that it can easily be changed later.
4. Write a program that reads a file containing data about the changing popularity of various baby names over time and
displays the data about a particular name. Each line of the file stores a name followed by integers representing the
name's popularity in each decade: 1900, 1910, 1920, and so on. The rankings range from 1 (most popular) to 1000
(least popular), or 0 for a name that was less popular than the 1000th name. The following lines are a sample of the
file format:
Sally 0 0 0 0 0 0 0 0 0 0 886
Sam 58 69 99 131 168 236 278 380 467 408 466
Samantha 0 0 0 0 0 0 272 107 26 5 7
Samir 0 0 0 0 0 0 0 0 920 0 798
Your program should prompt the user for a name and search the file for that name:
This program allows you to search through the
data from the Social Security Administration
to see how popular a particular name has been
since 1900.
Name? Sam
Search WWH ::




Custom Search