Ask Computer Engineering Expert

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

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91341880
  • Price:- $55

Guranteed 36 Hours Delivery, In Price:- $55

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As