Question: JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out the name of the student with the lowest gpa

JAVA HELP FOR COMP:

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 = " The student with the highest grade point average is ";

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

String name, bestStudent = null;

double gpa, highestGPA = NEGATIVE_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); else System.out.println (BEST_MESSAGE + bestStudent); } // method run

} // class HighestGPA

Students.dat file:

Larry 3.3 Curly 3.7 Moe 3.2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!