I am writing a program for an assignment that uses a jFrame UI to read the contents of a notepad file full of "grades" (A, B, C, C+ etc) and then calculate the total number of grades, and the highest and lowest grades. In the jFrame, the user inputs a file name (I do not want to use JFileChooser because that is not part of the assignment) and clicks "load" to load the file. I am struggling with the Load() method. So far, I have:
public ArrayList<LetterGrade> Load(File file) throws FileNotFoundException {
ArrayList<LetterGrade> grades = new ArrayList();
try{
Scanner input = new Scanner(file);
String grade = input.nextLine();
grades.add(LetterGrade.grade);
} catch (FileNotFoundException ex) {
System.out.printf("ERROR: %s", ex);
}
return grades;
I know that there is a problem in the line that says grades.add(LetterGrade.grade) because I can only add a LetterGrade enum (A, AMinus, BPlus, B etc) to the ArrayList "grades" whereas grade is a String. How can I make it so that when Scanner reads the file, it takes each grade and adds it to the ArrayList called "grades"? Also, I only want to take grades that are part of my LetterGrade enum, so would I use an if/else to filter that? Thanks for the help, and I will respond as quickly as possible to questions.