The feedback I get from. my mentor doesn't make sense...
package com.codegym.task.task19.task1916;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Tracking changes
*/
public class Solution {
//3. The Solution class must have a public static List<LineItem> field called lines that is initialized immediately.
public static List<LineItem> lines = new ArrayList<>();
public static void main(String[] args) throws IOException {
//4. In the main(String[] args) method, the program must read file names from the console (use BufferedReader).
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file1 = reader.readLine();
String file2 = reader.readLine();
//5. In the main(String[] args) method, the BufferedReader used for reading input from the console must be closed after use.
reader.close();
//6. The program must read the contents of the first and second file (use FileReader).
//Wrap it in a buffered reader as I want to use readLine()
BufferedReader reader1 = new BufferedReader(new FileReader(file1));
BufferedReader reader2 = new BufferedReader(new FileReader(file2));
//8. The lines list should contain the merged version of the lines from the files.
// Each line should start with the label ADDED, REMOVED, or SAME, depending on the action taken.
String line1, line2;
while(reader1.ready() && reader2.ready()){
line1 = reader1.readLine();
line2 = reader2.readLine();
if(line1.equals(line2)) lines.add(new LineItem(Type.SAME, line1));
else if (line2.isEmpty()) lines.add(new LineItem(Type.REMOVED, line1));
else lines.add(new LineItem(Type.ADDED, line2));
}
//7. The file input streams (FileReader) must be closed.
reader1.close();
reader2.close();
}
//2. The Solution class must have an enum called Type.
public static enum Type {
ADDED, // New line added
REMOVED, // Line deleted
SAME // No change
}
//1. The Solution class must contain a LineItem class.
public static class LineItem {
public Type type;
public String line;
public LineItem(Type type, String line) {
this.type = type;
this.line = line;
}
}
}