Results 1 to 6 of 6
  1. #1
    Victor is offline Master's Student
    Join Date
    Jan 2013
    Location
    Florida
    Posts
    13
    Rep Power
    0

    Post Grading Assignment

    Hello all, i am new to this community and currently enrolled in a Data Structures and Algorithms course. Java is the principle language. I am having a little trouble reading a .txt file containing grades, that is supposed to be referenced, when the user runs the program. It's supposed to show the amount of grades altogether, the AVG, MIN, and MAX, of the grades within the .txt file. I keep getting the following error when i run the program:
    Please enter the text file:
    examScores.txt
    Exception in thread "main" java.io.FileNotFoundException: C:\Users\iMac\workspace\Grading%20Assignment\bin\e xamScores.txt (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileReader.<init>(Unknown Source)
    at Grades.main(Grades.java:53)

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,926
    Rep Power
    8

    Default Re: Grading Assignment

    I'm not sure what you want us to do. It's telling you that it can't find that file. Is that file there? Are you absolutely sure? Check to make sure you're spelling everything correctly, including the usage of spaces.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Victor is offline Master's Student
    Join Date
    Jan 2013
    Location
    Florida
    Posts
    13
    Rep Power
    0

    Default Re: Grading Assignment

    I am having trouble with the program recognizing the .txt file. I was hoping that i may get a few ideas. It's located in the same area as my bin, src, and .settings folder for this project. And yet it doesn't open up the .txt file after typing in examScores.txt at the prompt.

  4. #4
    Victor is offline Master's Student
    Join Date
    Jan 2013
    Location
    Florida
    Posts
    13
    Rep Power
    0

    Default Re: Grading Assignment

    Here is the src code i have:
    import java.util.*;
    import java.io.*;
    import java.text.*;


    public class Grades
    {
    //This method produces the heading for the program or you may say that it introduces the program.
    public void introduction()
    {
    System.out.println("***Let's see those grades Einstein!!***");
    System.out.println();
    }

    @SuppressWarnings("resource")
    public static void main(String[] args) throws Exception
    {

    double sum = 0;
    int gradeCount = 0;
    int MAX = 0;
    int MIN = 0;
    double AVG = 0;
    int gCount = 0;
    int gCount1 = 0;
    int gCount2 = 0;
    int gCount3 = 0;
    int gCount4 = 0;
    int [] examGrades;
    char letterGrade;


    DecimalFormat df = new DecimalFormat("#.##");

    String[] currGrades;

    Scanner input = new Scanner(System.in);
    System.out.println("***Welcome to the Exam Statistics Program!!***");
    System.out.println();

    System.out.println("Please enter the text file: ");

    String txtFile = input.next();
    // FileReader fr = new FileReader("C:\\" + txtFile);
    FileReader fr = new FileReader(Grades.class.getProtectionDomain().getC odeSource().getLocation().getPath() + txtFile);
    Scanner input1 = new Scanner(fr);

    currGrades = input1.nextLine().split(" ");
    input1.close();
    examGrades = new int[currGrades.length];

    for(int g = 0; g< examGrades.length; g++)
    {
    examGrades[g] = Integer.parseInt(currGrades[g]);

    if (examGrades[g]<=0)
    {
    break;
    }

    gradeCount++;
    sum += examGrades[g];
    AVG = sum/gradeCount;

    if (examGrades[g] >= 0)
    {
    if (examGrades[g] < MIN)
    {
    MIN = examGrades[g];
    }
    else if (examGrades[g] > MAX)
    {
    MAX = examGrades[g];
    }


    if ((examGrades[g] <= 100) && (examGrades[g] >= 90))
    {
    letterGrade = 'A';
    }
    gCount++;
    if ((examGrades[g] >= 80) && (examGrades[g] >= 89))
    {
    letterGrade = 'B';
    }
    gCount1++;
    if ((examGrades[g] >= 70) && (examGrades[g] >= 79))
    {
    letterGrade = 'C';
    }
    gCount2++;
    if ((examGrades[g] >= 60) && (examGrades[g] >= 69))
    {
    letterGrade = 'D';
    }
    gCount3++;
    if ((examGrades[g] <= 59) && (examGrades[g] >= 0))
    {
    letterGrade = 'F';
    }
    gCount4++;
    }

    }

    System.out.println("The total number of grades is" + gradeCount);
    System.out.println("The maximun exam score is" + MAX);
    System.out.println("The minimum exam score is" + MIN);
    System.out.println("The average score of the exam grades is" + AVG);
    System.out.println("The number of A's is" + gCount);
    System.out.println("The number of B's is" + gCount1);
    System.out.println("The number of C's is" + gCount2);
    System.out.println("The number of D's is" + gCount3);
    System.out.println("The number of F's is" + gCount4);

    }

    }

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,935
    Rep Power
    19

    Default Re: Grading Assignment

    But is:
    C:\Users\iMac\workspace\Grading%20Assignment\bin\e xamScores.txt
    the actual location of the txt file?
    If not then that's the part you need to fix.
    Either move the file, or change the path.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Victor is offline Master's Student
    Join Date
    Jan 2013
    Location
    Florida
    Posts
    13
    Rep Power
    0

    Default Re: Grading Assignment

    I got it, thanks. It was pointing the wrong location all along, but what i did just to be sure, was delete my examScores.txt file, then created a new .txt file named exams, and placed it within the bin directory path, and it worked. Thanks for the replies.

Similar Threads

  1. Deleted post: Java Grading Program
    By Fubarable in forum Forum Lobby
    Replies: 0
    Last Post: 07-02-2012, 12:27 PM
  2. [Please Help] Grading Program
    By orange4 in forum New To Java
    Replies: 1
    Last Post: 08-18-2011, 10:15 PM
  3. assignment help
    By xyknight in forum New To Java
    Replies: 6
    Last Post: 03-13-2011, 07:19 PM
  4. Java Program: Grading using Arrays [Help]
    By Sly Cooper in forum New To Java
    Replies: 1
    Last Post: 01-30-2011, 07:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •