import java.io.*;
public class WordFinder
{
public static void main(String[] args)
{
new WordFinder();
}
public WordFinder()
{
find("a.txt","area");
find("b.txt","area");
find("a.txt","/male","deaths");
find("b.txt","/male","deaths");
}
public void find(String fileName,String word) // parameters
{
String find = word;
try
{
BufferedReader file = new BufferedReader(new FileReader( fileName ));
do
{
String w = file.readLine();
if (w.indexOf(find)>=0)
{ System.out.println(fileName +" " + w); }
} while (file.ready());
file.close();
}
catch (IOException ex)
{ System.out.println(ex.toString()); }
}
public void find(String fileName,String word,String another) // parameters
{ // POLYMORPHISM
try
{
BufferedReader file = new BufferedReader(new FileReader( fileName ));
do
{
String w = file.readLine();
if (w.indexOf(word)>=0 && w.indexOf(another)>=0 )
{ System.out.println(fileName +" " + w); }
} while (file.ready());
file.close();
}
catch (IOException ex)
{ System.out.println(ex.toString()); }
}
}
/**************
The program above searches for the String "population".
Then it prints the entire line of text
that contains the word "population".
population and culture were heavily shaped by immigrants from throughout
18.11 births/1,000 population (2008 est.)
7.43 deaths/1,000 population (2008 est.)
0 migrant(s)/1,000 population (2008 est.)
/total population:/ 0.97 male(s)/female (2008 est.)
/total population:/ 76.36 years
/total population:/ 97.2%
population, an export-oriented agricultural sector, and a diversified
Unfortunately, it does not print the total population
for the country.
Changing to "Population" doesn't quite solve the problem.
Population:
Population growth rate:
The files in the folder are named "a.txt", "b.txt" ...
(1) Look inside the files and figure out why the Population
number does not get printed. Explain the cause of the problem.
(2) By examining some of the files, figure out
how the program can be changed so that it prints
the total land area of a country.
***************/