1. Engineering
  2. Computer Science
  3. java help for comp can someone please modify the code...

Question: java help for comp can someone please modify the code...

Question details


Can someone please modify the code to create LowestGPA.java that prints out the name of the student with the lowestgpa.

In the attached zip file, you will find two files HighestGPA.java and students.dat. Students.dat file contains names of students and their gpa. Check if the code runs correctly in BlueJ or any other IDE by running the code. Modify the data to include few more students and their gpa.

import java.util.*; // for the Scanner class

import java.io.*; // for the File class

public class HighestGPA
public static void main (String[ ] args) throws FileNotFoundException
new HighestGPA().run();
} // method main   

public void run() throws FileNotFoundException
final double NEGATIVE_GPA = -1.0;

final String NO_VALID_INPUT =
"Error: the given file has no valid input.";

final String BEST_MESSAGE =
"\n\nThe student with the highest grade point average is ";

Scanner fileScanner = new Scanner (new File ("students.dat"));   

String name,
bestStudent = null;

double gpa,

while (fileScanner.hasNextLine())
Scanner lineScanner = new Scanner (fileScanner.nextLine());

name = lineScanner.next();
gpa = lineScanner.nextDouble();
if (gpa > highestGPA)
highestGPA = gpa;
bestStudent = name;
} // if
} // while
if (highestGPA == NEGATIVE_GPA)
System.out.println (NO_VALID_INPUT);
System.out.println (BEST_MESSAGE + bestStudent);
} // method run

} // class HighestGPA

Students.dat file:

Larry 3.3
Curly 3.7
Moe 3.2

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution