Write a program that will read in a file of student academic

Assignment Help Basic Computer Science
Reference no: EM13772121

Reading from and Writing to Text Files

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 PrintWriteroutFile 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. 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.

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

• A NumberFormatException if it can't parse an int or double when it tries to - this indicates an error in the 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.

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

// ************************************************************************

// Warning.java

//

// Reads student data from a text file and writes data to another text file.

// ************************************************************************

importjava.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)

{

intcreditHrs; // number of semester hours earned

doublequalityPts; // number of quality points earned

doublegpa; // 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);

Reference no: EM13772121

Questions Cloud

Write a program to display the duplicate values in an array : Write a program to display the duplicate values in an array.
What are some of the more subtle ways that economy can : Download and Read "Questions about Fiscal Policy: Implications from the Financial Crisis of 2008-2009." By N. Gregory Mankiw. After reading the article, answer the following questions: During the crisis of 2008-2009, the Obama's administration's stim..
Important and useful chemistry application : We will investigate radiocarbon dating, a very important and useful chemistry application -  In order to advance from one page to the next, you first need to correctly answer each of the questions on the current page.
Write a paper on the things they carried by tim obrien : Write a reasearch paper on "the things they carried" by tim obrien.
Write a program that will read in a file of student academic : 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
Differences between wages : The wage gap is described as the differences between wages earned by men and wages earned by women. For the alternative assignment answer the following questions:
What is your average total cost : What is your average total cost? Suppose you could produce one more (the fifth) widget at a marginal cost of $5. If you do produce that fifth widget, what will your average total cost be? Has your average total cost increased or decreased? Why
Write an equation for any changes observed : Write an equation for the formation of any precipitate.When i added the HCl, the solution became cloudy - write an equation for any changes observed.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Approach appropriate for company forefront of technology

However, adopting a secondary approach where others adopt early and a firm learns from their mistakes is often a viable strategy. When is each approach most appropriate and why?

  What are the pros and cons of each raid

Please explain how each RAID configuration works and what are the pros and cons of each RAID?

  Create a florida state information system

Create and use a Microsoft Access Database from which the program will retrieve the city information. Include 1 table with 5 fields per row, and 10 rows of data (cities).

  The head office of kkae

The head office of KKAE is located in Australia/Sing/India. Documents and reports must be displayed/printed in English. Grammar and spelling in all the documents and output reports follow the English version. For example, some of the foreign salutati..

  State the principle of defense in depth give two

define the principle of defense in depth. give two examples of how the principle might be applied one describing

  Write the method getcoinflips that takes a number of flips

Write the method getCoinFlips that takes a Coin and a number of flips as parameters. The method should return an array of the booleans produced by flipping the Coin the given number of times.

  Architecture to assist in the decision-making process

Using enterprise architecture to assist in the decision-making process, write a 1500 words paper in which you do the following:Determine activities that you believe would be appropriate for outsourcing.

  How you identify a protected item in a uml diagram of c

How would you identify a protected item in a UML diagram of C++

  Estimate for risk management in accompanying data

Estimate for risk management as shown in accompanying data, which vulnerability must be evaluated for additional controls first? Which one should be evaluated last?

  Explaining the available bandwidth as function of n

Assuming average packet size is 5 slot times, expreess the available bandwidth as a function of N?

  Determine probability that contention ends on round k

Determine the probability that a contention ends on round k, and what is a mean number of rounds per contention period?

  Create a shadow on the phrase html5 canvas

Create a shadow on the phrase "HTML5 Canvas" with an offset -x of 2px, an offset -y of 5px, a blur of 6px, and a text shadow color grey.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd