I've been trying to find the answer to this and can't seem to find it. I'm supposed to read a text file with student names and grades and find the lowest and highest grade. This is how far I've come. I'm able to find the highest and lowest grade. I can also find the name of the student with the highest grade but I cannot get the name of the one that has the lowest grade.
File ft = new File("Grades.txt");
Scanner scan = new Scanner(ft);
String names = "";
String beststudent = "";
String worsestudent = "";
do {
names = scan.next();
largest = parseInt(String.valueOf(scan.next()));
smallest = largest;
if (largestNumber > largest) {
worsestudent = names;
}
if (largestNumber < largest) {
smallestNumber = largestNumber;
largestNumber = largest;
beststudent = names;
}
} while (scan.hasNext());
}
The format of names are NAME_LASTNAME INTEGER in my text file if you were wondering.