Question
fill in the code can you solve it quickly please? import java.io.* ; import java.util.ArrayList; import java.util.Scanner ; /** This class contains a method compare()
fill in the code can you solve it quickly please?
import java.io.* ;
import java.util.ArrayList;
import java.util.Scanner ;
/**
This class contains a method compare() that checks if the corresponding lines (strings) in
two input text files, file1 and file2, are different.
If the two lines are the same it prints the line number followed by ":" followed by the line contents of file1 only
If the lines are different it prints (on a single line) the line number followed by ":" followed by the line of file1 followed by
a "|" followed by the line of file2
If file1 has a line but file2 does not (i.e. the number of lines in file1 is greater than the number in file2 then
it prints the line number followed by ":" followed by the line of file1 followed bya "|"
If file2 has a line but file1 does not (i.e. the number of lines in file2 is greater than the number in file1 then
it prints the line number followed by ":" followed by a "|" followed by the line of file2
You must use loops to compare the files.
NOTE: You may not import anything other than what is already imported.
*/
public class FileCompare
{
private String file1 ;
private String file2 ;
/**
Initializes instance variables
@param file1 the first file name
@param file2 the second file name
*/
public FileCompare(String file1, String file2)
{
this.file1 = file1 ;
this.file2 = file2 ;
}
/**
Write a method: public void compare() according to the instructions above
If either file1 of file2 does not exist, then a FileNotFoundException is
thrown automatically. The method compare() should not catch I/O exceptions
*/
//-----------Start below here. To do: approximate lines of code = 23
// Write the method
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
Step by Step Solution
3.41 Rating (157 Votes )
There are 3 Steps involved in it
Step: 1
FileComparejava import javaio import javautilArrayList import javautilScanner This class contains a method compare that checks if the corresponding li...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Document Format ( 2 attachments)
608c00a382098_208357.pdf
180 KBs PDF File
608c00a382098_208357.docx
120 KBs Word File
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started