The program should compute the GPA (grade point or quality point average) for each student (the total quality points divided by the number of semester hours), and display the student name if the gpa is less than 2.0. The file Warning.java contains a skeleton of the program. Do the following: 1. Add the code to calculate the gpa. 2. Display the name if the gpa is less than 2.0. 3. Test to ensure the output is accurate. 4. Add code to catch the following exceptions: • A FileNotFoundException if the input file does not exist. How will you test for this exception? • A NumberFormatException if it can’t parse an int or double when it tries to – this indicates an error in the input file format. How will you test for this error? Display the record number in error.
Review the
will contain the student name (a single String with no spaces), the number of semester hours earned (an integer),
the total quality points earned (a double).
Here is the students.dat data file:
students.dat
Smith 27 83.7
Jones 21 28.35
Walker 96 182.4
Doe 60 150
Wood 100 400
Street 33 57.4
Taylor 83 190
Davis 110 198
Smart 75 292.5
Bird 84 168
Summers 52 83.2
The program should compute the GPA (grade point or quality point average) for each student (the total quality
points divided by the number of semester hours), and display the student name if the gpa is less than 2.0. The
file Warning.java contains a skeleton of the program. Do the following:
1. Add the code to calculate the gpa.
2. Display the name if the gpa is less than 2.0.
3. Test to ensure the output is accurate.
4. Add code to catch the following exceptions:
• A FileNotFoundException if the input file does not exist.
How will you test for this exception?
• A NumberFormatException if it can’t parse an int or double when it tries to – this indicates an error
in the input file format. How will you test for this error?
Display the record number in error.
![```java
// ***************************************************************
// Warning.java
//
// Reads student data from a text file and writes data to another text file.
// ***************************************************************
import java.util.Scanner;
import java.io.*;
public class Warning
{
public static void main (String[] args) throws IOException
{
int creditHrs; // number of semester hours earned
double qualityPts; // number of quality points earned
double gpa; // grade point (quality point) average
String name; // student's name
// Set up scanner to input file
Scanner inFile = new Scanner(new File("g:\\students.dat"));
System.out.println ("\n Students on Academic Warning\n");
// Process the input file, one token at a time
while (inFile.hasNext())
{
// Get the credit hours and quality points and
// determine if the student is on warning. If so,
// display the student's name.
name = inFile.next();
creditHrs = Integer.parseInt(inFile.next());
qualityPts = Double.parseDouble(inFile.next());
// Insert gpa calculation
// and statement to determine if the student name is listed.
}
inFile.close();
//insert catch statements
}
}
```
This Java code is a part of a program that reads student data from a text file named `students.dat`. The program processes this data to determine if students are on academic warning based on their credit hours and quality points.
Key Steps in the Program:
- It uses the `Scanner` class to read input from the file.
- The number of credit hours, quality points, and the student's name are extracted from the file.
- Comments in the program indicate where further implementation for GPA calculation and warning determination should be done.
- The program should ideally close the file after reading data and include appropriate error handling.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9656a833-2928-468d-bda4-7d65920b0a10%2F755089fc-5d20-411e-941d-9fbf859b2c1a%2Fdkb0n8c_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images









