Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

Has the team been empowered to prioritize the issues?

Answered: 1 week ago

Question

Have issues been prioritized?

Answered: 1 week ago

Question

Has the priority order been provided by someone else?

Answered: 1 week ago