Question

Must be written in JAVA Code 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...

Must be written in JAVA Code

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:

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.

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. Compute the GPA, 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.

After the loop close the PrintWriter.

Think about the exceptions that could be thrown by this program: • A FileNotFoundException if the input file does not exist • A NumberFormatException if it can’t parse an int or double when it tries to - this indicates an error inthe input file format • An IOException if something else goes wrong with the input or output stream 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.

Test the program. Test data is in the file students.txt. Be sure to test each of the exceptions as well.

students.txt

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 2 92.5
Bird 84 168
Summers 52 83.2

Warning.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
{
        // -------------------------------------------------------------------
        // 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)
        {
                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
                {
                // 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 ()
                        {
                        // 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.
                        }
                // Close output file
                }
        catch (FileNotFoundException exception)
                {
                        System.out.println ("The file " + inputName + " was not
                        found.");
                }
        catch (IOException exception)
        {
                System.out.println (exception);
        }
        catch (NumberFormatException e)
        {
                System.out.println ("Format error in input file: " + e);
        }
        }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.
Here is the completed code for this problem.  Let me know if you have any doubts or if you need anything to change.
Thank You !!
========================================================================================

// ************************************************************************
// 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 {
    // -------------------------------------------------------------------
    // 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) {
        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 {
            // Set up scanner to input file
            Scanner scanner = new Scanner(new File(inputName));
            // Set up the output file stream
            PrintWriter outFile = new PrintWriter(new FileWriter(outputName));
            // 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 (scanner.hasNext()) {
                line = scanner.nextLine();
                // Get the credit hours and quality points and
                creditHrs = Integer.parseInt(line.split("\\s+")[1]);
                qualityPts = Double.parseDouble(line.split("\\s+")[2]);
                gpa = qualityPts / creditHrs;
                // determine if the student is on warning. If so,
                // write the student data to the output file.
                if (gpa < 1.5 && creditHrs < 30) {
                    outFile.write(line + "\r\n");
                } else if (gpa < 1.75 && creditHrs < 60) {
                    outFile.write(line + "\r\n");
                } else if (gpa < 2) {
                    outFile.write(line + "\r\n");
                }
            }
            // Close output file
            outFile.close();
        } catch (FileNotFoundException exception) {
            System.out.println("The file " + inputName + " was not found.");
        } catch (IOException exception) {
            System.out.println(exception);
        } catch (NumberFormatException e) {
            System.out.println("Format error in input file: " + e);
        }
    }
}

======================================================================================

Warning javax 1l class Warning 13 // Reads student data (name, semester hours, q 14 File Edit Format View Help // text file,

thanks !

Add a comment
Know the answer?
Add Answer to:
Must be written in JAVA Code 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...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. The data file studentData.txt contains a list of student's name, major, grade points, and cred...

    please solve this Java program. I need some explain. 2. The data file studentData.txt contains a list of student's name, major, grade points, and credit hours. The number of students is unknown. The data file is on D2L. studentData.txt Major Grade Points Credit Hours Name Jacob Michael Joshua Matthew Samantha CS Math CS Art Business 42 80 48 39 100 12 25 12 10 34 UK Write a program that reads the data from the data file, calculates the GPA...

  • (Java) Rewrite the following exercise below to read inputs from a file and write the output...

    (Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...

  • Description: This Java program will read in data from a file students.txt that keeps records of...

    Description: This Java program will read in data from a file students.txt that keeps records of some students. Each line in students.txt contains information about one student, including his/her firstname, lastname, gender, major, enrollmentyear and whether he/she is a full-time or part-time student in the following format. FIRSTNAME      LASTNAME        GENDER              MAJORENROLLMENTYEAR FULL/PART The above six fields are separated by a tab key. A user can input a keyword indicating what group of students he is searching for. For example, if...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

  • Please provide the full code...the skeleton is down below: Note: Each file must contain an int...

    Please provide the full code...the skeleton is down below: Note: Each file must contain an int at the beginning, stating the number of records in the file. Afterwards, the number of records in the file will follow. Each record that follows will consist of a last name (String), and a gpa (double). However, to test the error handling of your program, the number of records will not always match the int value. All possible combinations should be tested. 1.) Prompt...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Write a C++ program to store and update students' academic records in a binary search tree....

    Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should contain the following information fields:               1) Student name - the key field (string);               2) Credits attempted (integer);               3) Credits earned (integer);               4) Grade point average - GPA (real).                             All student information is to be read from a text file. Each record in the file represents the grade information on...

  • Write a java program to create a student file which includes first name, last name, and...

    Write a java program to create a student file which includes first name, last name, and GPA. Write another Java program to open the students file. Display the students list and calculate the average GPA of the class.  

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT