Java code: Instructions are in first image. Skeleton code in the second.

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
100%
Java code: Instructions are in first image. Skeleton code in the second.
Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be
written to a file. 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).
The following shows part of a typical data file:
Smith 27 83.7
Jones 21 28.35
Walker 96 182.4
Doe 60 150
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) then
write the student information to the output file if that student should be put on academic warning. A student will be on warning if he/she has a GPA less than 1.5 for
students with fewer than 30 semester hours credit, 1.75 for students with fewer than 60 semester hours credit, and 2.0 for all other students.
The file Warning.java contains a skeleton of the program. Do the following:
1. Set up a Scanner object scan from the input file and a PrintWriter outFile to the output file inside the try clause (see the comments in the program). Note that
you'll have to create the PrintWriter from a FileWriter,but you can still do it in a single statement.
2. Inside the while loop add code to read and parse the input get the name, the number of credit hours, and the number of quality points. Test the number of
semester hours earned if less than zero or greater than 120 throw to an exception handler class with message and exit program. Compute the GPA. Test the GPA
when greater than 4.0 or less than zero throw to an exception handler class with message and exit program. Determine if the student is on academic warning,
and if so write the name, credit hours, and GPA (separated by spaces) to the output file.
3. After the loop close the PrintWriter.
4. Think about the exceptions that could be thrown by this program:
• A FileNotFoundException if the input file does not exist
o A NumberFormatException if it can't parse an int or double when it tries to - this indicates an error in the input file format
o An InputMismatchException
o An IOException if something else goes wrong with the input or output stream
• An all purpose exception
Add a catch for each of these situations, and in each case give as specific a message as you can. The program will terminate if any of these exceptions is thrown, but
at least you can supply the user with useful information.
5. Test the program. Test data is in the file students.dat. Be sure to test each of the exceptions as well.
Transcribed Image Text:Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. 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). The following shows part of a typical data file: Smith 27 83.7 Jones 21 28.35 Walker 96 182.4 Doe 60 150 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) then write the student information to the output file if that student should be put on academic warning. A student will be on warning if he/she has a GPA less than 1.5 for students with fewer than 30 semester hours credit, 1.75 for students with fewer than 60 semester hours credit, and 2.0 for all other students. The file Warning.java contains a skeleton of the program. Do the following: 1. Set up a Scanner object scan from the input file and a PrintWriter outFile to the output file inside the try clause (see the comments in the program). Note that you'll have to create the PrintWriter from a FileWriter,but you can still do it in a single statement. 2. Inside the while loop add code to read and parse the input get the name, the number of credit hours, and the number of quality points. Test the number of semester hours earned if less than zero or greater than 120 throw to an exception handler class with message and exit program. Compute the GPA. Test the GPA when greater than 4.0 or less than zero throw to an exception handler class with message and exit program. Determine if the student is on academic warning, and if so write the name, credit hours, and GPA (separated by spaces) to the output file. 3. After the loop close the PrintWriter. 4. Think about the exceptions that could be thrown by this program: • A FileNotFoundException if the input file does not exist o A NumberFormatException if it can't parse an int or double when it tries to - this indicates an error in the input file format o An InputMismatchException o An IOException if something else goes wrong with the input or output stream • An all purpose exception Add a catch for each of these situations, and in each case give as specific a message as you can. The program will terminate if any of these exceptions is thrown, but at least you can supply the user with useful information. 5. Test the program. Test data is in the file students.dat. Be sure to test each of the exceptions as well.
Run Arguments
1 //
2// Warning.java
3//
4// Reads student data from a text file and writes data to another text file.
5 // ***.
6 import java.util.Scanner;
7 import java.io.*;
8 public class Warning
7/
/ Reads student data (name, semester hours, quality points) from a
//text file, computes the GPA, then writes data to another file
// if the student is placed on academic warning.
//
public static void main (String[] args)
10
11
12
13
14
15
16
17
int creditHrs; // number of semester hours earned
double qualityPts; // number of quality points earned
double gpa; // grade point (quality point) average
String line, name, inputName = "students.dat";
String outputName = "warning.dat";
try
18
19
20
21
22
23
24
// Set up scanner to input file
// Set up the output file stream
// Print a header to the output file
outFile.println ();
outFile.println ("Students on Academic Warning");
outFile.println ();
// Process the input file, one token at a time
while ()
25
26
27
28
29
30
31
32
33
// Get the credit hours and quality points and
// determine if the student is on warning. If so,
// write the student data to the output file.
34
35
36
37
38
// Close output file
39
40
catch (FileNotFoundException exception)
41
42
System.out.println ("The file " + inputName +
* was not found.");
43
44
catch (1OException exception)
45
46
System.out.println (exception);
47
48
catch (NumberFormatException e)
49
50
System.out.println ("Format error in input file: " + e);
51
52
53}
Transcribed Image Text:Run Arguments 1 // 2// Warning.java 3// 4// Reads student data from a text file and writes data to another text file. 5 // ***. 6 import java.util.Scanner; 7 import java.io.*; 8 public class Warning 7/ / Reads student data (name, semester hours, quality points) from a //text file, computes the GPA, then writes data to another file // if the student is placed on academic warning. // public static void main (String[] args) 10 11 12 13 14 15 16 17 int creditHrs; // number of semester hours earned double qualityPts; // number of quality points earned double gpa; // grade point (quality point) average String line, name, inputName = "students.dat"; String outputName = "warning.dat"; try 18 19 20 21 22 23 24 // Set up scanner to input file // Set up the output file stream // Print a header to the output file outFile.println (); outFile.println ("Students on Academic Warning"); outFile.println (); // Process the input file, one token at a time while () 25 26 27 28 29 30 31 32 33 // Get the credit hours and quality points and // determine if the student is on warning. If so, // write the student data to the output file. 34 35 36 37 38 // Close output file 39 40 catch (FileNotFoundException exception) 41 42 System.out.println ("The file " + inputName + * was not found."); 43 44 catch (1OException exception) 45 46 System.out.println (exception); 47 48 catch (NumberFormatException e) 49 50 System.out.println ("Format error in input file: " + e); 51 52 53}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
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