Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Writing a java program and I need it to search one text file,personnel_addresses2.txt for any any cities names that contain the word Wax and then

Writing a java program and I need it to search one text file,personnel_addresses2.txt for any any cities names that contain the word Wax and then take the names of the people that live in those cities and search for those names in another text file, personnel_salaries2.txt, but right now its only returning the first result when there should be 13,586. And also is this an efficient way to do this? If not can you show me a more efficient way please since the files have over 200,000 entries.

Code:

import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.*; import java.util.*;

class A { public static void main(String[] args) throws IOException { File f1 =new File("personnel_addresses2.txt"); //Creation of File Descriptor for input file File f2 = new File("personnel_salaries2.txt"); String[] words = null; //Intialize the word Array String[] salary = null; List list = new ArrayList(); FileReader fr = new FileReader(f1); //Creation of File Reader object BufferedReader br = new BufferedReader(fr); //Creation of BufferedReader object FileReader f2r = new FileReader(f2); BufferedReader b2r = new BufferedReader(f2r); String s; String d; String Name; String City; String Person; String Sal; String input="Wax"; // Input word to be searched while((s= br.readLine())!=null) //Reading Content from the file { words = s.split("\\|"); Name = words[0]; City = words[1];

for (String word : words) { if (word.equals(input)) //Search for the given word { //list.add(Name); while((d = b2r.readL System.out.println(name);ine()) != null) { salary = d.split("\\|"); Person = salary[0]; Sal = salary[1]; for (String sal : salary) { if(sal.equals(Name)) { System.out.println(d); } } }

} } } fr.close(); f2r.close();

personnel_addresses2.txt(partial)

Japheth Edwards|Albany Evan Taylor|Wax Olivia Grimme|Wax Alfonso McNeil|Somerset Allyson Schroeder|Washington April Tomes|Lancaster Laura Hancock|Louisville Robert Joyce|Remington HamedHaribHamed Yates|Somerset Robin Snoke|Remington David Bash|Versailles Boyko Michels|Washington

personnel_salaries2.txt(partial)

Jessica Collett|59789 Mitchell Long|68985 Khumbo Benedict|53385 Adam Kandibanda|67671 Lloyd Wathen|98564 Daniel Towery|36588 Suzanne Siferd|97528 James Gudger|67113

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions

Question

Show that the language L = {a^i b^i c^ki i Answered: 1 week ago

Answered: 1 week ago

Question

To solve p + 3q = 5z + tan( y - 3x)

Answered: 1 week ago