This is for my beginning Java class. There are similar questions asking to sort the values that are given in an array; I know how to do that, but here I need to read in a text file, and then sort the values and display them by employee name and the hours that they worked, while also keeping the order from most to least. This is what the text file looks like:
Jim 4 5 6 1 2 3 4
Harry 6 5 1 3 9 2 0
John 2 3 1 6 7 8 4
Lisa 2 1 5 4 1 2 6
And here is all that I know about reading in text files and my current code for this project.
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class EmployeeWorkHours {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
File file = new File("/Users/ODonnell/Desktop/inputData.txt");
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
System.out.println(line);
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}