This is my program it reads from a file but I was away for the lecture for file readers so I’m winging it.
This program currently reads in one line and prints out the top 3 values from it but it only works with one line in the file.
import java.util.*;
import java.io.*;
public class ProcessdatdereFile
{
public static void main (String[] args)throws IOException{
List namenum=readM("data/raw.txt");
dataProcess(namenum);
}
public static List readM(String filename)throws IOException{
Scanner fr=new Scanner(new FileReader(filename));
List<String>namenum=new ArrayList<String>();
while(fr.hasNext()){
namenum.add(fr.next());
}
fr.close();
Collections.sort(namenum,Collections.reverseOrder());
return namenum;
}
public static void dataProcess(List namenum)throws IOException{
for(int i=0;i<4;i++){
System.out.printf("%s ",namenum.get(i));
}
System.out.println("");
}
}
raw.txt contains
Mary 45 87 23 76
Joe 34 76 12 78 34 87
Anne 90 5 99
The program needs to print each name and the top 3 scores on individual lines.
Lengthy replies are welcome.
Thanks in advance.
Ive changed these two methods so that it processes them as a line each rather than each string in the file. It now takes each Line and prints it out with the name and 3 top scores.