Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: This Program doesn't run completely, what do I need to fix? Please Help

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default This Program doesn't run completely, what do I need to fix? Please Help

    import java.io.*;
    import java.util.Scanner;
    class ExamAnalysis
     {
       public static void main (String [] args) throws FileNotFoundException
       {
           System.out.println ("I hope you are ready to begin...");
     
           Scanner keyboard = new Scanner(System.in);  
     
           System.out.println();
     
           System.out.println("Please type the correct answers to the exam questions, one right after the other: ");
     
           String answers = keyboard.nextLine();
     
           System.out.println("Where is the name of the file containing each student's responses to the 10 questions? ");
     
           String responses = keyboard.nextLine();
     
           Scanner read = new Scanner(new File(responses));
     
     
     
            while (read.hasNextLine())
     
            {
     
              int i = 0;
     
              int numberOfStudents = 9;
     
              while (i < numberOfStudents && read.hasNextLine())
     
               {
     
                responses = read.nextLine();
     
                i++;
     
                System.out.println("Student # " + i + "'s"+ " responses: " + responses.substring(0,10));
     
               }
     
                System.out.println("We have reached 'end of file'!");
     
                System.out.println();
     
                System.out.println("Thank you for the data on "+ numberOfStudents +" students. Here's the analysis: ");
     
                resultsByStudents(responses, answers);
     
                analysis(responses, answers);
     
               }
     
            }
     
     
     
             public static void resultsByStudents(String responses, String answers)
     
              { 
     
               System.out.println ("Student #        Correct        Incorrect       Blank");
     
               System.out.println ("~~~~~~~~~        ~~~~~~~        ~~~~~~~~~       ~~~~~");
     
               int student = 0;
     
               int correct = 0;
     
               int incorrect = 0;
     
               int blank = 0;
     
     
     
             for (int i = 0; i < 9; i++) 
     
             {
     
              for (int j = 0; j < responses.length(); j++)
     
              {
     
               if ((responses.charAt(j)) == answers.charAt(j))
     
                correct++; 
     
               else if ((responses.charAt(j)) != answers.charAt(j))
     
                incorrect++;
     
               else 
     
                blank++;   
     
                }
     
                 System.out.println(student + "        " + correct + "        " + incorrect + "        " + blank);
     
                 student++;
     
            }    
     
          }
     
     
     
         public static void analysis(String responses, String answers)
     
         {
     
          System.out.println("QUESTION ANALYSIS   (* marks the correct response)");
     
          System.out.println("~~~~~~~~~~~~~~~~~");
     
     
     
     
     
     
     
        double A = 0.0;
     
        double B = 0.0;
     
        double C = 0.0;
     
        double D = 0.0;
     
        double E = 0.0;
     
        double X = 0.0;
     
     
     
     
     
        for (int i = 1; i < 10; i++) 
     
        {
     
         for (int j = 0; j < responses.length(); j++) 
     
         {
     
     
     
          int chooseA = 0;
     
          int chooseB = 0;
     
          int chooseC = 0;
     
          int chooseD = 0;
     
          int chooseE = 0;
     
          int chooseBlank = 0;
     
     
     
          A = chooseA/9;
     
          B = chooseB/9;
     
          C = chooseC/9;
     
          D = chooseD/9;
     
          E = chooseE/9;
     
          X = chooseBlank/9;
     
     
     
          String a = "A";
     
          String b = "B";
     
          String c = "C";
     
          String d = "D";
     
          String e = "E";
     
          String blank = "Blank";
     
     
     
          if (responses.charAt(j) == A)
     
           chooseA++;
     
          else if (responses.charAt(j) == B)
     
           chooseB++;
     
          else if (responses.charAt(j) == C)
     
           chooseC++;
     
          else if (responses.charAt(j) == D)
     
           chooseD++;
     
          else if (responses.charAt(j) == E)
     
           chooseE++;
     
          else 
     
           chooseBlank++; 
     
     
     
         System.out.println("Question #" + i);
     
         if       (answers.charAt(i) == 'A') a = "A*"; 
     
         else if  (answers.charAt(i) == 'B') b = "B*"; 
     
         else if  (answers.charAt(i) == 'C') c = "C*";
     
         else if  (answers.charAt(i) == 'D') d = "D*";
     
         else if  (answers.charAt(i) == 'E') e = "E*";
     
        System.out.println(a + "        " + b + "        " + c + "        " + d + "        " + e + "        " + blank);
     
        System.out.println (chooseA + "        " + chooseB + "        " + chooseC + "        " + chooseD + "        " + chooseE + "        " + chooseBlank );
     
        System.out.println (A + "        " + B + "        " + C + "        " + D + "        " + E + "        " + X);
     
       }
     
      } 
     
     } 
     
    }
    Attached Files Attached Files


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: This Program doesn't run completely, what do I need to fix? Please Help

    Welcome shafat

    Please post the code on the forum rather than as an attachment so we can see it, and please use code tags, see the Announcements page if you need help.

    "runs but doesn't fully work" ... tells us nothing about what it does and what it should do. Please be very specific about what happens now and what you want to happen.
    If there is an error message copy-paste the full text of the error message on the forum with the code. The more details you provide, the more likely you are to get a helpful reply

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: This Program doesn't run completely, what do I need to fix? Please Help

    Sorry, I have updated the code.

  4. #4
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: This Program doesn't run completely, what do I need to fix? Please Help

    Which part doesn't run completely also please attach text file you were reading in.

  5. #5
    Junior Member
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: This Program doesn't run completely, what do I need to fix? Please Help

    The analysis method doesn't run completely, the questions get printed many times and the records aren't recorded properly:

    here is what it prints (this is the part where it doesn't run completely, above this the program works as it should be.)


    QUESTION ANALYSIS (* marks the correct response)
    ~~~~~~~~~~~~~~~~~
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #1
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #2
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #3
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #4
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #5
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #6
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #7
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #8
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0
    Question #9
    A B C D E Blank
    0 0 0 0 0 1
    0.0 0.0 0.0 0.0 0.0 0.0

  6. #6
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: This Program doesn't run completely, what do I need to fix? Please Help

    yeah i saw

  7. #7
    Junior Member
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: This Program doesn't run completely, what do I need to fix? Please Help

    Yeah, how do I fix it? it's also not reading the file with answers on it. :/

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,803
    My Mood
    Mellow
    Thanks
    176
    Thanked 626 Times in 613 Posts

    Default Re: This Program doesn't run completely, what do I need to fix? Please Help

    This is one of those occasions when the code is doing exactly as programmed, and it's difficult to see what you need help with. If you trace the logic in the analysis() method, you'll see the program is doing exactly what you've programmed it to do. If that is not what you want, then you need to ask a specific question. Put it in the form:

    The program is doing this:

    (Provide a sample of the existing behavior, copy/paste a sample run from your terminal.)

    But I need it to do this:

    (Edit the existing behavior or describe how it should be different.)

    Then provide the current code or, preferably, an SSCCE with all necessary data files that can be run to duplicate the issue. Include any error messages you're getting that you want help with.
    it's also not reading the file with answers on it.
    I think you should lead with this problem and give us the details we need to help you fix it. Without the answer file, the rest of the program is pretty pointless.

  9. #9
    Member llowe29's Avatar
    Join Date
    Jul 2013
    Posts
    116
    My Mood
    Tired
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: This Program doesn't run completely, what do I need to fix? Please Help

    Make sure you put txt file youre reading in the same folder as class. Also every students answers, should be in the same file.

Similar Threads

  1. Replies: 7
    Last Post: May 8th, 2013, 02:33 PM
  2. Replies: 1
    Last Post: November 2nd, 2012, 04:16 PM
  3. [SOLVED] How can i fix and run my program?? Please help..
    By BeginCode in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 7th, 2012, 08:03 PM
  4. Code compiles fine but doesn't run Properly
    By nadirkhan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 9th, 2011, 11:46 AM
  5. GUI doesn't work when synchronized method is run
    By worwhite in forum AWT / Java Swing
    Replies: 1
    Last Post: August 1st, 2011, 07:59 AM