Java Reference
In-Depth Information
**12.29
(
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
j
if
j
is a single
digit. For example, a file named
Exercise2_1
in a directory will be renamed to
Exercise2_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_29 *
**12.30
(
Occurrences of each letter
) Write a program that prompts the user to enter
a file name and displays the occurrences of each letter in the file. Letters are
case-insensitive. Here is a sample run:
Enter a filename: Lincoln.txt
Number of A's: 56
Number of B's: 134
...
Number of Z's: 9
*12.31
(
Baby name popularity ranking
) The popularity ranking of baby names from
in files named
babynameranking2001.txt
,
babynameranking2002.txt
, . . . ,
babynameranking2010.txt
. Each file contains one thousand lines. Each line
contains a ranking, a boy's name, number for the boy's name, a girl's name,
and number for the girl's name. For example, the first two lines in the file
babynameranking2010.txt
are as follows:
1
Jacob
21,875
Isabella
22,731
2
Ethan
17,866
Sophia
20,477
So, the boy's name Jacob and girl's name Isabella are ranked #1 and the boy's
name Ethan and girl's name Sophia are ranked #2. 21,875 boys are named
Jacob and 22,731 girls are named Isabella. Write a program that prompts the
user to enter the year, gender, and followed by a name, and displays the ranking
of the name for the year. Here is a sample run:
Enter the year: 2010
Enter the gender: M
Enter the name: Javier
Javier is ranked #190 in year 2010
Enter the year: 2010
Enter the gender: F
Enter the name: ABC
The name ABC is not ranked in year 2010
Search WWH ::
Custom Search