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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Review the program Warning.java that reads in a file of student academic credit data. Each line of the input file
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.
Transcribed Image Text:```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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY