I have a list of Date/time, CPM numbers separated by commas. I have to read through the file and put it in an ArrayList sorted by the max CPM numbers and only keeping the lines containing the top 5 CPMs.
public class Geiger implements Comparable<Geiger> {
private String date;
private int CPM;
public static void main(String[] args) {
List<String> dGeigers = new ArrayList<>();
try {
BufferedReader br = new BufferedReader(new FileReader("test.txt"));
String nextLine;
while ((nextLine = br.readLine()) != null) {
if (nextLine.contains("Every Minute")) {
String[] values = nextLine.split(",");
Collections.addAll(dGeigers, values[0] + "\t" + values[2] + "\n");
}
}
} catch (IOException e) {
e.printStackTrace();
}
Collections.sort(dGeigers);
System.out.println(dGeigers.toString());
}
public Geiger(String date, String cPM2) {
this.date = date;
this.CPM = Integer.valueOf(cPM2);
}
public String getDate() {
return date;
}
public int getCPM() {
return CPM;
}
public String toString() {
return date + "\t" + CPM;
}
@Override
public int compareTo(Geiger cpmSort) {
if (this.CPM < cpmSort.CPM) {
return -1;
} else if (this.CPM == cpmSort.CPM) {
return 0;
} else {
return 1;
}
}
}
Here is the code I have so far. It manages to sort by the first column, which would be the Date/time, but I can't figure out how to sort it by the CPM column.
This
is
a
11111, Every Minute, 14
00231, Every Minute, 24
00011, Every Minute, 30
00201, Every Minute, 25
00201, Every Minute, 26
00301, Every Minute, 7
00401, Every Minute, 566
02301, Every Minute, 3230
02301, Every Minute, 3540
00231, Every Minute, 214
test file
sdfasdf asdfadg sdfh sghsgfh sfgh sfdg sdgh
here is the test file that I used.