Results 1 to 6 of 6
Thread: Grading Assignment
- 01-29-2013, 04:50 PM #1
Master's Student
- Join Date
- Jan 2013
- Location
- Florida
- Posts
- 13
- Rep Power
- 0
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)
- 01-29-2013, 04:52 PM #2
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!
- 01-29-2013, 05:15 PM #3
Master's Student
- Join Date
- Jan 2013
- Location
- Florida
- Posts
- 13
- Rep Power
- 0
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.
- 01-29-2013, 05:17 PM #4
Master's Student
- Join Date
- Jan 2013
- Location
- Florida
- Posts
- 13
- Rep Power
- 0
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);
}
}
- 01-29-2013, 05:24 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 01-29-2013, 05:37 PM #6
Master's Student
- Join Date
- Jan 2013
- Location
- Florida
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Deleted post: Java Grading Program
By Fubarable in forum Forum LobbyReplies: 0Last Post: 07-02-2012, 12:27 PM -
[Please Help] Grading Program
By orange4 in forum New To JavaReplies: 1Last Post: 08-18-2011, 10:15 PM -
assignment help
By xyknight in forum New To JavaReplies: 6Last Post: 03-13-2011, 07:19 PM -
Java Program: Grading using Arrays [Help]
By Sly Cooper in forum New To JavaReplies: 1Last Post: 01-30-2011, 07:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks