I can't figure out what im doing wrong with my File I/O program lol

I'm new to the java language and was wondering if anybody could help me with the program i an writing. I don't quite understand file I/O but I've given it my best and I'm stuck. I'm supposed to 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 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 instructions are :
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 the input file—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 and Scanner objects in a finally block.
4. Think about the exceptions that could be thrown by this program:
• A FileNotFoundException if the input file does not exist
• A InputMismatchException if it can’t read 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.txt. Be sure to test each of the exceptions as well.
My source code is:
// Warning.java
// Reads student data from a text file and writes data to another text file.
import java.util.*;
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
     Scanner scan=null;
     PrintWriter outFile=null;
     String name, inputName = "students.txt";
     String outputName = "warning.txt";
     try
          // Set up Scanner to input file
          scan=new Scanner(new FileInputStream(inputName));
          // Set up the output file stream
          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 (scan.hasNext())
               // 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.
               name=scan.next();
               creditHrs=scan.nextInt();
               qualityPts=scan.nextDouble();
               gpa=qualityPts/creditHrs;
               if ((gpa < 1.5 && creditHrs < 30) || (gpa < 1.75 && creditHrs < 60) || (gpa < 2.0 && creditHrs >= 60))
                    outFile.print(name + " ");
                    outFile.print(creditHrs + " ");
                    outFile.print(qualityPts + " ");
                    outFile.print(gpa);
          //Add a catch for each of the specified exceptions, and in each case
          //give as specific a message as you can
catch (FileNotFoundException e)
System.out.println("The file " + inputName + " was not found.");
catch (IOException e)
System.out.println("The I/O operation failed and " + outputName + " could not be created.");
catch (InputMismatchException e)
System.out.println("The input information was not of the right type.");
          //Close both files in a finally block
finally
     scan.close();
     outFile.close();
The txt file is:
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 will run and then terminate without creating warning.txt. How can I get it to create the warning .txt file? Any help that you could give would be greatly appreciated.

Alright, here is my code reposted:
// Warning.java
// Reads student data from a text file and writes data to another text file.
import java.util.;
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
Scanner scan=null;
PrintWriter outFile=null;
String name, inputName = "students.txt";
String outputName = "warning.txt";
try
// Set up Scanner to input file
scan=new Scanner(new FileInputStream(inputName));
// Set up the output file stream
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 (scan.hasNext())
// 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.
name=scan.next();
creditHrs=scan.nextInt();
qualityPts=scan.nextDouble();
gpa=qualityPts/creditHrs;
if ((gpa < 1.5 && creditHrs < 30) || (gpa < 1.75 && creditHrs < 60) || (gpa < 2.0 && creditHrs >= 60))
outFile.print(name " ");
outFile.print(creditHrs " ");
outFile.print(qualityPts " ");
outFile.print(gpa);
//Add a catch for each of the specified exceptions, and in each case
//give as specific a message as you can
catch (FileNotFoundException e)
System.out.println("The file " inputName " was not found.");
catch (IOException e)
System.out.println("The I/O operation failed and " outputName + " could not be created.");
catch (InputMismatchException e)
System.out.println("The input information was not of the right type.");

Similar Messages

  • HEAVY disk access and I can't figure out what's doing it

    Since installing Snow Leopard, I'm running into period of heavy disk usage (not idle). I can't seem to figure out what it is, because as soon as I get Activity Monitor up, it's calmed down. It's similar in usage to Spotlight indexing, but that's not what it is. The only thing I notice is the Quick Look Helper seems to at 16% CPU usage when this happens, quickly dropping below 1%. Anyone have any ideas of what I might look for? Is there a log I could check to see disk access?

    Hi,
    You could look at the Console.app in the Utilities folder and the 'top' command in the Terminal.app

  • Anyone having or had a problem with kernel_task running uploads in back ground and can't figure out what its doing

    My iMac is running kernel_task and using a lot of upload bandwidth. I talked to isp this morning he said that I was topping out on the upload side while download was normal. He also said that it started about 3 weeks ago but I've been looking and trying to remember what I did as far as installing or changing setting and I can't figure it out, also using a magicjack on computer but tried without it and still the same and its hard to use the phone when other party only gets every other 4 or 5 words. HELP PLEASE!! driving me crazy.

    You have something that is uploading data from your network, so you may have a runaway application doing this. If you quit all your running applications does the problem still exist? If so then you may have a corrupted system process.
    Open Activity Monitor in the Utilities folder.  Select All Processes from the Processes dropdown menu.  Click twice on the CPU% column header to display in descending order.  If you find a process using a large amount of CPU time (>=70,) then select the process and click on the Quit icon in the toolbar.  Click on the Force Quit button to kill the process.  See if that helps.  Be sure to note the name of the runaway process so you can track down the cause of the problem.
    Create a new user account with admin status, then log out of your account and log into the new account. Does the problem still exist?
    Also, try basic repairs:
    Repair the Hard Drive and Permissions - Lion/Mountain Lion
    Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Repair
    When the recovery menu appears select Disk Utility. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported then click on the Repair Permissions button. When the process is completed, then quit DU and return to the main menu. Select Restart from the Apple menu.

  • A simple networking program, I can't figure out what's gone wrong

    hi, dear all, I programmed a simple server and client, I try to type some in client and see it on the server side, but the server doesn't show the input from client. Please help me out, thanks a lot.
    there are two classes, server and client.
    server class:
    import java.net.*;
    import java.io.*;
    public class test3 {
    /** Creates a new instance of test3 */
    public test3() {
    public static void main(String[] args) {
    try {
    ServerSocket server = new ServerSocket(5555);
    while (true) {
    Socket connection = server.accept( );
    try{
    // OutputStreamWriter out
    // = new OutputStreamWriter(connection.getOutputStream( ));
    // out.write("You've connected to this server.\r\n");
    // out.flush();
    InputStream in = connection.getInputStream( );
    StringBuffer input = new StringBuffer( );
    int c;
    // connection.close( );
    int i = 0;
    while(i < 10){
    while ((c = in.read( )) != -1) input.append((char) c);
    String inString = input.toString().trim( );
    System.out.println(inString);
    i++;
    catch (IOException e) {
    // This tends to be a transitory error for this one connection;
    // e.g. the client broke the connection early. Consequently,
    // we don't want to break the loop or print an error message.
    // However, you might choose to log this exception in an error log.
    /* finally {
    // Most servers will want to guarantee that sockets are closed
    // when complete.
    try {
    if (connection != null) connection.close( );
    catch (IOException e) {}
    catch (IOException e) {
    System.err.println(e);
    client class:
    import java.net.*;
    import java.io.*;
    public class test4{
    public static void main(String[] args){
    try{
    Socket theSocket = new Socket("192.168.1.102", 5555);
    OutputStream theOutputStream = theSocket.getOutputStream();
    OutputStreamWriter out = new OutputStreamWriter(theOutputStream);
    BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
    String theLine = userIn.readLine( );
    if (theLine.equals(".")) break;
    System.out.println(theLine);
    out.write(theLine + "\r\n");
    out.flush( );
    // System.out.println(networkIn.readLine( ));
    }// end of while
    }// end of try
    catch (IOException e) {
    System.err.println(e);
    }// end of catch
    } // end of main
    } // end of test4
    Thanks again

    Well, i don't get the error to, but I use the DataOutputStream and DataInputStream or ObjectOutputStream and ObjectInputStream with the I/O connection.
    the basic steps at the server are:
    1) create new ServerSocket
    2) Waiting for a connection
    3) Create a I/O Stream
    4) Process the job
    5) close the connection
    at the client are:
    1) connect to the server
    2) Create a I/o stream
    3) process the job
    4) close the connection
    Maybe you can send what the specify error you get in your code

  • Can't figure out what I'm doing wrong

    I'm using Studio 8 in Mac OS X (10.4.6). I've got some pdfs
    uploaded to my site that are accessible through links one one of
    the pages. I had to make changes to the pdfs and resave them. I
    thought I uploaded them, but when I test the links it downloads the
    old version and I can't figure out what I'm doing wrong. Here's
    what I did.
    This may be a dumb way to do things, but I saved the new
    version and then dragged into the server file in
    user-->Library-->Application
    Support-->Macromedia-->Dreamweaver
    8-->Configuration-->ServerConnections-->unnamed
    server-->public_html (this is where all the other files are).
    When I go back into Dreamweaver and open the pdf listed in the
    Files window on the right (by control-clicking and selecting Open
    with-->Acrobat) the correct version appears. I thought maybe
    there was a delay or something, but I've waited and still the old
    version is what you get from the site.
    Is there an easier way to do this, or is something wrong
    maybe? Many thanks in advance.

    > This may be a dumb way to do things, but I saved the new
    version and then
    > dragged into the server file in
    user-->Library-->Application
    > Support-->Macromedia-->Dreamweaver
    Put the files in this Site's Local Site Folder.
    If unsure of where you've specified this to be, look in this
    site definition
    (dw menu-->Sites-->Manage or Edit Sites)
    If that path you've given above above is correct, it's
    wrong....

  • I uninstalled Firefox once, reinstalled it and it ran. I had a problem so I did it again. Now it will not run and I get an error message saying that firefox is running and you can only run one at a time. I can't figure out what is running.

    Because of a problem, I uninstalled Firefox once, reinstalled it and it ran. I had a problem so I uninstalled/reinstalled it again. Now it will not run. I get an error message saying that firefox is running and you can only run one at a time. I have uninstalled multiple times and can't figure out what is running. The is only one Firefox installed and it is not open. What does this mean and how do I fix it?

    If you use ZoneAlarm Extreme Security then try to disable Virtualization.
    *http://kb.mozillazine.org/Browser_will_not_start_up#XULRunner_error_after_an_update
    See also:
    *[[/questions/880050]]

  • Background program running and can't figure out what it is...

    I have an IMAC desktop, I just purchased the Photoshop Elements 10 software for MAC, installed it, running fine. But now I have program that is contanstly running in the background that is slowing up all of my other applications I run while I'm working. I've checked the Activity Monitor but I can't see anything out of the norm...Does anyone have any suggestions? I'm very frustrated....

    I presume you mean that the hard drive is working on something. Again, any such process would show in the Activity Monitor. Check that again, confirming that you have "all processes" set so you can see everthing that's going on. It will be easiest to spot anything unusual if you click on the "% CPU" column header to sort by the amount of CPU time each process is using. Click twice so that the arrow is pointing downwards; then the top users of CPU time will be listed at the top. Post the name of any process that's consistently or unexpectedly using a significant amount of CPU time and we can probably figure out what's happening and offer suggestions.
    Regards.

  • Am getting message from MacPro that my start up disc is full - but I can't find it and can't figure out what to do to help situation. I've been making a number of imovies, which generates junk files. help?

    I am getting message from MacPro that my start up disc is full - but I can't find this "start up disc" and can't figure out what to do to help situation. I've been making a number of imovies, which generates junk files and material that I should toss in the trash, but it is not clear to me  what items I can toss and which items I can't toss. Can you help? Using the imovie "help" support the system showed me under the menu item "go" where the "start up disc" should be - but that wasn't actually available on my menu!  Thanks for your help!

    Disk Utility 
    Get Info on the icon on Desktop
    Try to move this to the MacBook Pro forum
    Your boot drive should be 30% free to really perform properly. 10% minimum
    Backup, clone, use TimeMachine, use another drive for your projects and movies, replace and upgrade the internal drive even.

  • Trouble with calculating fields. Can't select (check) fields. Also can't figure out what's wrong with a division field (percent) that I created. Keep getting the pop up that format of the field doesn't allow blah blah blah... Help!

    Trouble with calculating fields. Can't select (check) fields. Also can't figure out what's wrong with a division field (percent) that I created. Keep getting the pop up that format of the field doesn't allow blah blah blah... Help!

    1. Use the mouse to select the field and then press the space bar.
    2. A null string is the same as zero. What is the result for division by zero?

  • When I put my iphone 4s into my pocket (pants or coat) and move it around, the phone beeps/makes a tone. I can't figure out what is causing the noise.

    I have a strange problem. When I put my iphone 4S into my pocket (pants or coat) and move it around, the phone makes a beep noise/tone. I can't figure out what is causing the noise. It doesn't sound like any of my regular applications. Maybe it is the lock noise but I can't tell for sure.  More movement makes more beeps.  Even walking with my phone in my pocket creates beeps.  The IOS is 7.0.4 (11B554a).  Anyone else have this crazy problem?

    Try This...
    Close All Open Apps... Sign Out of your Account... Perform a Reset...
    Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430
    If the issue persists...
    Connect to iTunes on the computer you usually Sync with and Restore
    http://support.apple.com/kb/HT1414
    Make sure you have the Latest Version of iTunes (v11) Installed on your computer
    iTunes free download from www.itunes.com/download

  • I have a MacBook Pro OS 10.9.5 with 250 GB hard drive-- I can't figure out what is taking up all my hard drive space (it is not backups).  Any ideas?

    MacBook Pro OS 10.9.5, 250 GB solid state hard drive.
    I can't figure out what is taking up all my hard drive space (it is not backups).  Any ideas? 

  • I probably misclicked when I activated the security lock on the iPhone and now I can not figure out what password I entered. Moreover, I have patches and funky looking phone so I can not restore iphine pres itunes. Please advice.

    I probably misclicked when I activated the security lock on the iPhone and now I can not figure out what password I entered. Moreover, I have patches and funky looking phone so I can not restore iphine pres itunes. Please advice.

    Your only recourse is to force it into DFU mode:
    Turn your phone off and connect your cable to the computer, but not the device just yet. Start up iTunes. Now, hold down the home button on your phone and plug it in to the cable - don't let go of the button until iTunes tells you it's detected a phone in recovery mode. Now you can restore to factory settings.

  • I see "imac-54f9d5" under the "Shared" heading in my finder. I am not connected to any printers or other Mac devices. Is it possible that someone is remotely accessing my system? How can I figure out what this is?

    I see "imac-54f9d5" under the "Shared" heading in my finder. I am not connected to any printers or other Mac devices. Is it possible that someone is remotely accessing my system? How can I figure out what this is?

    is it your imac?
    is it your your router's name?
    are you by any chance connected to another wifi router then your own because the other one was open and not password protected?

  • TS3694 My iPad says it has to restore to update, but it will not.  It is caught in a cycle of not being able to restore but needed to restore.  I keep getting error code 3014 but I can not figure out what this means!

    My iPad says it has to restore to update, but it will not.  It is caught in a cycle of not being able to restore but needed to restore.  I keep getting error code 3014 but I can not figure out what this means! nor can I do anything about it!  So Frutrated!

    Also...
    See Here  >  http://support.apple.com/kb/HT1808
    You may need to try this More than Once...
    But... if the Device has been Modified... this will Not necessarily work.

  • I recently received a  WD My Book Studio external Hard drive and am installing it but can't figure out what the difference between wd turbo installer  64 and wd   turbo installer is.  Can someone tell me.  Thanks in advance for all your help.

    I recently received a  WD My Book Studio external Hard drive and am installing it but can't figure out what the difference between wd turbo installer  64 and wd   turbo installer is.  Can someone tell me.  Thanks in advance for all your help.

    Oh ok, well that was what the test said prior to reformatting the hard drive. Now, it doesn't find any trouble no matter how many times I run it. That's what has me so confused, everything seems to check out and yet...I can't do anything, not even install the software!

Maybe you are looking for

  • Restauração pelo itunes

    é o seguinte , meu iphone é o 4s de 64 gb , e ele nao é daqui do Brasil , ele é do japao , e eu fui restaurar ele pelo itunes e pediu cartao SIM , mais aí nao tenho , como faço pra desbloquear e voltar a usar ele normal sem chip ? agora nao tem como

  • Exchange 2013 ECP Login fails HTTP 404 Requested URL: /owa/auth/logon.aspx

    Hi, One of our Exchange servers stopped allowing access to OWA and ECP. I have now managed to get OWA working but ECP is still failing. When connecting to ECP using https://servername/ecp/ it asks me for my username and password. After hitting enter

  • Document management Issues with Alternate Access Mapping

    hi,   I am using share-point 2010,I have done the AAM as follows:  Internal URL                                         Zone                          Public URL for Zone  http://109.XX.XX.XX:101                      Default                        htt

  • Exchanging 3GS for 4 -- What happens to Applecare?

    I bought my 3GS & AppleCare from an AT&T store on May 16th. I now know I probably shouldn't have, but I registered AppleCare that same day. I went to AT&T today and they allowed me to pre-order the iPhone4. Then when I pick it up, I'll return my 3GS

  • Period Work Schedule in TM

    If Monday to Friday Gen shift timing is 9.30 to 6pm & Saturday half day  9.30 to 2pm. So can define in PWS , Monday to friday same DWS & friday other DWS & Sunday OFF. Monday-Friday ---One DWS Saturday---- Other DWS & Sunday - OFF,  is it correct? Re