1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lord [1]
3 years ago
8

Geraldine's Landscaping Service and Gerard's Lawn Maintenance are merging their businesses and want to merge their customer file

s. Each file contains a customer number, last name, address, and property area in square feet, and each file is in customer number order. Design the logic for a program that merges the two files into one file containing all customers. Assume there are no identical customer numbers.
Computers and Technology
1 answer:
irina [24]3 years ago
3 0

Answer:

Check the explanation

Explanation:

Steps to follow:-

Read file1 or file2

Get number from line of file1

Check numberlist contains this number

if number is not in numberlist then add number to numberlist

Write line of file1 to outputFile

Read file2

Get number from line of file2

Check numberlist contains this number  

if number is not in numberlist then add number ot numberlist

Write line of file2 to outputFile

Repeat the above process untill file line is not null

Complete Java code:-

import java.io.*;

import java.util.*;

public class Solution {

   public static void main(String[] args)

   {

       mergerFiles();

   }

 public static void mergerFiles()

 {

     try {

        FileReader fileReader1 = new FileReader("res/file1");

         BufferedReader bufferedReader1 = new BufferedReader(fileReader1);

         FileReader fileReader2 = new FileReader("res/file2");

         BufferedReader bufferedReader2 = new BufferedReader(fileReader2);

         FileWriter fileWriter = new FileWriter("res/outputfile");

         BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

         String file1Line=null;

         String file2Line=null;

         Set<String> set=new HashSet();

         while(((file1Line = bufferedReader1.readLine()) != null) || (file2Line = bufferedReader2.readLine())!= null) {

             String number1=file1Line.split(",")[0].split(":")[1];

             if(set.add(number1))

             {

                 bufferedWriter.write(file1Line+"\n");

             }

             if((file2Line = bufferedReader2.readLine())!= null) {

                 String number2 = file2Line.split(",")[0].split(":")[1];

                 if (set.add(number2)) {

                     bufferedWriter.write(file2Line+"\n");

                 }

             }

         }

         bufferedWriter.close();

     } catch (FileNotFoundException e) {

         e.printStackTrace();

     } catch (IOException e) {

         e.printStackTrace();

     }

 }

}

File1 content:-

number:1234567890, lastname: Kumar, address: delhi, property:2000 sqft

number:2234567890, lastname: Chaudhari, address: Pune, property:4000 sqft

number:3234567890, lastname: Singh, address: Mumbai, property:2500 sqft

number:4234567890, lastname: Varma, address: Kolkata, property:5000 sqft

number:5234567890, lastname: Sinha, address: Patna, property:6000 sqft

File2 content:-

number:4234567890, lastname: Ram, address: bangalore, property:25000 sqft

number:6234567890, lastname: Rajput, address: Ranchi, property:40400 sqft

number:3234567890, lastname: Sinha, address: Gurgaon, property:25300 sqft

number:4234567890, lastname: Kaur, address: Chennai, property:50200 sqft

number:8234567890, lastname: Mehta, address: Pondicherry, property:26000 sqft

Output file content:-

number:1234567890, lastname: Kumar, address: delhi, property:2000 sqft

number:4234567890, lastname: Ram, address: bangalore, property:25000 sqft

number:2234567890, lastname: Chaudhari, address: Pune, property:4000 sqft

number:6234567890, lastname: Rajput, address: Ranchi, property:40400 sqft

number:3234567890, lastname: Singh, address: Mumbai, property:2500 sqft

number:5234567890, lastname: Sinha, address: Patna, property:6000 sqft

number:8234567890, lastname: Mehta, address: Pondicherry, property:26000 sqft

You might be interested in
A document format is
anyanavicka [17]

Answer:

A document file format is a text or binary file format for storing documents on a storage media, especially for use by computers. There currently exist a multitude of incompatible document file formats.

Explanation:

8 0
3 years ago
Read 2 more answers
the list of available fonts in the fonts gallery may differ, depending on what fonts you have installed and the type of printer
aalyn [17]
I believe the correct answer is true. The <span>list of available fonts in the fonts gallery may differ, depending on what fonts you have installed and the type of printer you are using. Not all fonts would be available in all computers and for all printers. It should be installed first before use.</span>
5 0
3 years ago
When students have computer trouble they usually are expected to
Kitty [74]

Answer: A) Make any simple fixes on their own.

5 0
3 years ago
Read 2 more answers
The part of the eye thats similar to the film of a camera is the
Lapatulllka [165]
The retina is the part pf the eye that is similar to the film of a camera. It is a thin layer of cells that is located at the back of the eyeball. This part contains photoreceptor cells which respond to light where the neural signals received undergoes complex processing by other neurons in the retina.
3 0
3 years ago
Which of the following may present a problem for Linux users?
motikmotik
Tendancy to crash hope that helped
6 0
3 years ago
Read 2 more answers
Other questions:
  • The unique global address for a web page or other resource on the internet is called the ________.
    7·1 answer
  • Write a program that asks the user for three names, then prints the names in reverse order.
    5·1 answer
  • What kind of value should an employee possess when employees are expected to be responsible and fair?
    7·1 answer
  • Why laptop computer is called micro computer?​
    8·1 answer
  • Jared recently sent an email to all the members of his department asking them for their opinions about where the department shou
    11·1 answer
  • Given a list ` = (x1 x2 . . . xn−1 xn), we define two rotations of the list: The left-rotation is (x2 . . . xn−1 xn x1) and, lik
    12·1 answer
  • Your task is to identify three or more ways that big data is being collected on a regular basis, including one data collection m
    9·1 answer
  • A motor is controlled by a logic circuit. The circuit has inputs (0 or 1) from three sensors
    8·1 answer
  • Do pc players ever go outside?
    11·2 answers
  • 1 punto
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!