i hava this method separateOfficers() that will read from the input text file, record by record (line by line), writing into the appropriate output text file (officers registered in 2021, 2022 and 2023 will be stored in awc21.txt, awc22.txt and awc23.txt,respectively), and also counting the number of officers in each output file.
public static void SeparateOfficers() {
try {
readfile = new BufferedReader(new FileReader("awc.txt"));
String line = readfile.readLine();
String newline;
PrintWriter write21 = new PrintWriter(new FileOutputStream("awc21.txt"));
PrintWriter write22 = new PrintWriter(new FileOutputStream("awc22.txt"));
PrintWriter write23 = new PrintWriter(new FileOutputStream("awc23.txt"));
int a21=0,a22=0,a23=0;
while (line != null) {
newline = line;
StringTokenizer tokenizer = new StringTokenizer(line);
String s = (tokenizer.nextToken()).substring(0, 2);
switch (Integer.parseInt(s)) {
case 21 ->{
write21.println(newline);
a21++;
}
case 22 ->
{
write22.println(newline);
a22++;
}
case 23 ->
{
write23.println(newline);
a23++;
}
default -> {
System.out.println("*This UOB numbers is not in the specific range*");
System.out.println(newline + "\n");
}
}
line = readfile.readLine();
}
write21.close();
write22.close();
write23.close();
} catch (FileNotFoundException e) {
System.out.println("File Not Found");
} catch (IOException e) {
System.out.println("Error reading from the file");
}
}
and i cant make a unit test method foe it. it should Identify a minimal test set, as a set of records in testOfficers.txt for testing this method and insert it, as comment, at the beginning of the testing method. The output files will be testOfficers21.txt, testOfficers22.txt and testOfficers23.txt.