Given a list of patient demographics for several patients, we want to be able to group the data by patients with the same name. The demographics provided are (in order): Patient ID, Patient Name, Patient Sex, and Patient Date Of Birth. For example, here's a sample input:
PID1,POND^AMY,F,19890224
PID2,WILLIAMS^RORY,M,19881102
PID3,POND^AMY,F,19890224
PID4,CLARA^OSWALD,F,19890224
PID5,POND^AMY,F,20010911
PID6,CLAR^OSWALD,F,19890224
PID7,POND^AMELIA,F,20010911
PID8,CLARA^oswald,F,19890224
PID9,TYLER^ROSE,F,20000101
PID10,NOBLE^DONNA,F,19780405
PID11,TYLER^ROSE,F,20000101
PID12,NOBLE^DONN,F,19780405
PID13,TYLER^ROSE,F,20000102
PID14,CLARA^OSWALD^COLEMAN,F,19890224
The expected output is:
0:
PID1,POND^AMY,F,19890224
PID3,POND^AMY,F,19890224
PID5,POND^AMY,F,20010911
1:
PID2,WILLIAMS^RORY,M,19881102
2:
PID4,CLARA^OSWALD,F,19890224
PID8,CLARA^oswald,F,19890224
PID14,CLARA^OSWALD^COLEMAN,F,19890224
3:
PID6,CLAR^OSWALD,F,19890224
4:
PID7,POND^AMELIA,F,20010911
5:
PID9,TYLER^ROSE,F,20000101
PID11,TYLER^ROSE,F,20000101
PID13,TYLER^ROSE,F,20000102
6:
PID10,NOBLE^DONNA,F,19780405
7:
PID12,NOBLE^DONN,F,19780405
I will attempt this code:
import java.io.bufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.printWriter;
import java.util.ArrayList;
import java.util.Collection;
public class FileReaderWriter
{
public static void main(String[]args) throws IOException
{
BufferedReader reader = null ;
PrinterWriter outputStream = null;
ArrayList<String> rows = new ArrayList<String>();
try{
reader = new BufferedReader( new FileReader("Input.txt"));
outputstream = new PrintWriter(new FileWriter("Output.txt"));
String file;
while ((file = reader.readLine())!= null){
rows.add(file);
}
Collections.sort(rows);
String[] strArr = rows.toArray(new String[0]);
for(String cur : strArr);
outputStream.println(cur);
} finally {
if(reader != null){
reader.closr();
}
if(outputStream != null){
outputStream.close();
}
}
}
}