I don't know why my code isn't working, Can you see what is wrong?

I'm putting together a program that reads input from a text file and then decides what type of input it is (male or female) and then calculates the final sum for both.
m=male and f=female. The numbers after the letter are GPAs. Here is the input file:
m 2.4
f 3.2
m 3.7
m 4.0
f 2.9
f 1.8
f 3.8
m 1.7
m 3.4
f 2.6
m 2.8
m 1.7
f 3.7
m 3.9
f 4.0
f 3.6
m 2.3
f 2.9
m 3.0
m 2.7now here is my code:
import java.io.*;
import java.util.*;
public class gradecalc {
     * @param args the command line arguments
    public static void main(String[] args)
                            throws FileNotFoundException{
        // TODO code application logic here
double sumMale=0;
int numMale=0;
double sumFemale=0;
int numFemale=0;
char gender;
double gpa;
     Scanner inFile= new Scanner(new FileReader("gpa.txt"));
        PrintWriter outFile= new PrintWriter("gpaResult.txt");
while (inFile.hasNext())
    gender= inFile.next().charAt(0);
    gpa= inFile.nextDouble();
    switch (gender)
        case 'M':
        case 'm':
            sumMale= sumMale + gpa;
            numMale++;
            break;
        case 'F':
        case 'f':
            sumFemale= sumFemale + gpa;
            numFemale++;
            break;
        default:
            System.out.println("Invalid gender code: "+gender);
outFile.print("Sum of male students GPAs: " + sumMale);
outFile.print("Sum of female students GPAs: " + sumFemale);
outFile.close();
}and this is the error message I get when I build and then try to run the program:
init:
deps-jar:
compile:
run:
Exception in thread "main" java.util.NoSuchElementException
        at java.util.Scanner.throwFor(Scanner.java:838)
        at java.util.Scanner.next(Scanner.java:1461)
        at java.util.Scanner.nextDouble(Scanner.java:2387)
        at gradecalc.main(gradecalc.java:32)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)I feel like I have the code right, yet it doesn't output anything to my file and gives me the above exception. What's the problem here??

I actually figured it out. I think some of you programmers out there would be proud of me if you saw this completed code. This forum has really helped me out, but I still make some stupid mistakes. Like the one I realized I made on this program seconds after I made this pose. I realized that I had an unknown character at the end of my input document, which you can't see in my post because I must have not copied and pasted that part. I would delete this post, but don't know how.

Similar Messages

  • I keep getting "Unable to connect" for my firefox. It was working yesterday and I turned my computer off. I can get to the web using internet explorer 9. I don't know why my firefox is not working. Everything else is working. HELP....

    I keep getting "Unable to connect" for my firefox. It was working yesterday and I turned my computer off. I can get to the web using internet explorer 9. I don't know why my firefox is not working. Everything else is working.

    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.com/kb/Server+not+found
    *https://support.mozilla.com/kb/Firewalls

  • Day after yesterday night, my iphone 4s full off, I don't know why? but not oppen and not charging. What do I do?

    Day after yesterday night, my iphone 4s full off, I don't know why? but not oppen and not charging. What do I do?

    Plug it in to power for at least 15 minutes.  If it doesn't automatically come on, try a Reset... press the home and sleep/lock buttons until you see the Apple logo, ignoring the slider. Takes about 5-15 secs of button holding and you won't lose any data or settings.

  • I don´t know, why event counter doesn´t work

    Hi, I have a problem. I use DAQ 6221 and when I configure in test panel of Measurement & Automation the edge counting, this is functional. Now I trie to run the code example of DAQmx ANSI C Dev, CntDigEv_Fn and the code ran, I hadn't problem, but the counter wasn't functional. I don´t know what's wrong. Please If somebody know, please tell me. It´s very important.

    Hi,
    The first thing that I would make sure is that you have the correct device number in the example you are trying to run. That is, the default for this program is dev1, and if this is not the same as in MAX then obviously your program won't run. So, make sure that these are the same, and let me know either way what happens.
    George

  • I have bought new apple iPad but I don't know how to verify my Apple ID can you please help me

    I Have bought new apple I pad but I don't know how to verify it can you please help me

    When you create an iTunes account you should receive an email to the primary email address that you put on the account - that email should have a 'verify now' link in it which you need to click on and which will open a browser for you to log into your account from.
    From Frequently asked questions about Apple ID :
    How do I verify my Apple ID by email?
    Simply follow the link in the verification email that says "Verify Now." Sign in with your current Apple ID and password, then click Verify Address. You can also verify by signing in at My Apple ID. You'll receive an email prompting you to verify.
    (For info these are user-to-user forums, you are not talking to iTunes Support nor Apple, nor is it 'live chat' - a fellow user will reply when they see a question and they know the answer.)

  • HT5699 I don't know my answers to the identity questions, can you help me?

    I don't know any of my answers to the identity questions, can you help me?

    Go back to the article you asked this question from and use one of the methods of contacting Apple. The people on these boards can't reset your security questions.
    (95441)

  • I don't understand why my loop isn't working. Can someone help, please?

    public class PolarMain {
         public static void main(String[] args) {
              Polar p1 = new Polar(45, 50, 10, 10);
              System.out.println(" X1 " +p1.x1 +" New X1 " + p1.newX(45, 50 , 10 , 10)
               + " Y1 " +p1.y1 +" New Y1 " + p1.newY(45, 50 , 10 , 10));
         Polar p2 = new p2();
         for (i = 1; i < 10; i++)
         p2 = new (47, 49, 7, 7)
         System.out.println(" X1 " +p1.x1 +" New X1 " + p1.newX(47, 49 , 7 , 7)
               + " Y1 " +p1.y1 +" New Y1 " + p1.newY(47, 49, 7 , 7));
         I get the error message "illegal start of type" on line 14 and "identifier expected" on line 18.
    TIA.
         }

    see comments:
    public class PolarMain {
        public static void main(String[] args) {
            // this code below is all within the main method... no problem
            Polar p1 = new Polar(45, 50, 10, 10);
            System.out.println(" X1 " +p1.x1 +" New X1 " + p1.newX(45, 50 , 10 , 10)
             + " Y1 " +p1.y1 +" New Y1 " + p1.newY(45, 50 , 10 , 10));
        // all of the code below here is within NO method.  Big problem.
        Polar p2 = new p2(); // what is new p2()?  Do you have a class p2 or an object p2.
        for (i = 1; i < 10; i++)
        p2 = new (47, 49, 7, 7)   // this is way out in left field.  new .... what?  no class name
        System.out.println(" X1 " +p1.x1 +" New X1 " + p1.newX(47, 49 , 7 , 7)
             + " Y1 " +p1.y1 +" New Y1 " + p1.newY(47, 49, 7 , 7));
        }This all suggests to me that in order for you to progress, in order for you to be at a level where we can advise you, you must study and understand the fundamentals of java first. We could re-write this code for you to get it to work, but for what purpose? You need to go over the introductory tutorials asap.
    Good luck!

  • I don't know why my sound is not working

    all of a sudden my sound is not working

    @Katmar,
    What is the product number?
    Go to device manager and expand the sound category.  Is the sound card listed with an error?  If it has an error, open the device and let me know the status message.
    If it is a recent issue, have you tried a system restore?
    ↙-----------How do I give Kudos?| How do I mark a post as Solved? ----------------↓

  • Does anyone know why my slider isn't working?

    hello. I have a a slider which I am using on other sites and it works fine but i've just uploaded it to another site and it doesn't seem to load any of the images. It can be found here:  http://chumpspotter.com/chinapalace/restaurant/

    WordPress takes a LOT of web server space. If you have adequate bandwidth, that should not be a problem.
    In your source code, this is the path to your first banner image which cannot be found. 
    http://chumpspotter.com/chinapalace/restaurant/banner1.jpg
    If your images are on that domain, in which folder are they?
    Nancy O.

  • I don't know why in games kingdom conquest i can't buy cp

    i was buy cp from this game(kingdom conquest) it ok , but today when i buy this game cp tell me contact itunes support to complete this transaction.
    i think some things wrong? would you help me check what problm please
    <Edited By Host>

    These are user-to-user forums, you are not talking to Apple here and they don't monitor these forums. You can contact iTunes support here : http://www.apple.com/support/itunes/contact/ - click on Express Lane, then iTunes > iTunes Store

  • Hello my name is Vittorio about 2 years agoi've bought an student teacher licensed cs6 master collection, which worked quite well until recently. I don't know why but now it quit working, and keeps asking for my serial number. When i enter my serial numbe

    Hello my name is Vittorio. 2 years ago i've bought the CS6 master collection which has worked perfectly until recently.
    Now i keep getting the question to enter my serial number and when i do that i get the Invalid reaction. But it is the same number that worked before! What can i do to make CS6 work again?

    Hi Vittorio,
    We would like to know if you have re-installed your product on this machine. We would also like to know your OS version.
    Meanwhile, try:
    Error "The serial number is not valid for this product" | Creative Suite
    Invalid serial number error
    Error "Invalid serial number" | Acrobat 9 | CS4
    -Atul Saini

  • I don't understand why my code is not working please help!

    import(flash.events.MouseEvent);{
    stop();
    button1.addEventListener(MouseEvent.CLICK,showpic1);
    button1.addEventListener(MouseEvent.CLICK,showpic2);
    button1.addEventListener(MouseEvent.CLICK,showpic3);
    button1.addEventListener(MouseEvent.CLICK,showpic4);
    function showpic1(Event:MouseEvent);{
              gotoAndstop("pic1");
    function showpic2(Event:MouseEvent);{
              gotoAndstop("pic2");
    function showpic3(Event:MouseEvent);{
              gotoAndstop("pic3");
    function showpic4(Event:MouseEvent);{
              gotoAndstop("pic4");

    And another thing. Event (with capital E) is a particular datatype in AS3. You should avoid using reserved words. The handlers should look like this:
    function showpic1(event:MouseEvent);
              gotoAndStop("pic1");

  • I don't know why my screensaver does not work...

    I Set up my screensaver through system preferences, but it doesn't go to screensaver mode on my laptop after the time it should begin..

    Reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
    *Press and hold Shift and left-click the Reload button.
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Command + Shift + R" (MAC)
    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do not click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    You can check for problems caused by recent Flash updates and try these:
    *disable a possible RealPlayer Browser Record Plugin extension for Firefox and update the RealPlayer if installed
    *disable protected mode in Flash 11.3 and later
    *disable hardware acceleration in the Flash plugin
    *http://kb.mozillazine.org/Flash#Troubleshooting

  • I built an application to store de front panel of vi in a JPEG image file, but native labels of controls and indicator are unclear after image capture, some one knows why? I have a working example you can test.

    For some label colors like yellow or green, this defect is almost invisible, but for black color or any dark tone like brown or dark gray after file creation appears unclear labels.

    In more details, JPEG uses lossy compression and is not really suitable for cartoon-like pictures with objects containing high-contrast sharp features such as lines and boxes (as found in front panels). This has to do with the truncation in the 2D cosine transforms which gives you weak ripples near sharp edges, not visible in typical photographs.
    Of course you could set the quality to 100% (optional input) for no truncation with a trade-off of larger files, but it's pretty pointless. JPEG is only meant to be used for photographs.
    PNG is a fantastic format (intended as a GIF replacement), uses lossless compression, and wins in all aspects over jpeg for your intended use. All modern applications can deal with them (e.g. you can insert them into word or powerpo
    int) and any modern browser can display them. (see e.g. the PNG home site for more info).
    LabVIEW Champion . Do more with less code and in less time .

  • I can't hear the music playing when I have my headphones plugged in and I do not know why. And my headphones aren't broken. What is wrong?

    For some reason I cannot hear music when I plug in my headphone on my ipad, but headphines are not broken.

    Have you very used headphones or earbuds with an iPad before? It really takes quite a firm push to seat the earphones into the jack, you do have to give it a good push.

Maybe you are looking for

  • My battery is getting drained in two hours after getting hot. What's the solution?

    My battery is getting drained in two hours after getting hot. What's the solution?

  • Solaris 01/06 Kernel panic at ipf

    The system has three ethernet interfaces (Broadcom 5703, using bge driver). I added a line to ipf.conf to block an ip address and restarted ipfilter. 5-10 minutes later system rebooted and then freezed. I had to power down the system manually and the

  • ISE Profiling1

    Hi, I am using cisco ise and wlc, at the moment I am not doing posturing or anything, just profiling. Seems like it's unable to get past APPLE-Device for iphones, and for laptops it's showing unknown. I have set all the profling options to ON. Is the

  • Serializing objects that use Loggers

    i am trying to clean-up a lot of java code i have written. so please allow me one more post: the issue is objects that use Loggers : public class MyClass implements Serializable {   private static Logger logger = Logger.getLogger("baselib.utilities")

  • Problem with regex being used to filter filenames ...

    I wrote a simple FilenameFilter that takes a regular expression (String) in it's constructor. It uses that regex to determine which files to return when a directory is read using the listFiles(FilenameFilter) syntax. The problem I'm having is probabl