Results 1 to 6 of 6
Thread: Grade Book class, please help
- 12-11-2011, 01:34 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
Grade Book class, please help
I have to do a multiclass program and there's a logic error that I can't figure out.
public void inputStudents() throws FileNotFoundException //This will work to interactively input Students
{
Scanner inF = new Scanner(new File("C:\\Users\\Caili\\Documents\\Sophmore\\AP Computer Science\\Unit 4\\TextFile.txt"));
while(inF.hasNextLine( ))
{
Student aStudent = new Student();
aStudent.inputInfo("Name",inF.nextLine( ));
aStudent.inputInfo("Tests",inF.nextLine( ));
aStudent.inputInfo("Programs",inF.nextLine( ));
aStudent.inputInfo("Homework",inF.nextLine( ));
aStudent.computeAve();
aStudent.computeGrade();
myStudents.add(aStudent); It says that this line is null when I try to run it.
}
I have this that goes along with the method
public void inputInfo(String scoresType,String info)
{
if(scoresType.equals("Name"))
myName = info;
else if(scoresType.equals("Tests"))
myTests.getScores(info);
else if(scoresType.equals("Programs"))
myProgs.getScores(info);
else if(scoresType.equals("Homework"))
myHk.getScores(info);
}
public void getScores(String lineNumbers) //Interactively read scores from the keyboard into an array (-999 terminates input)
{
Scanner lineScan = new Scanner(lineNumbers);
while(lineScan.hasNext())
{
int num = lineScan.nextInt();
myScores[mySize] = num;
mySize++;
}
}
- 12-11-2011, 01:54 AM #2
Re: Grade Book class, please help
Does the variable myStudents have a valid value or is its value null?
Where do you define it and where do you give it a value?
- 12-11-2011, 02:32 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
Re: Grade Book class, please help
I declare it in the constucter
public ClassList()
{
ArrayList<Student> myStudents = new ArrayList<Student>();
int[] myGradeDistribution = new int[GREATEST_SIZE];
count = 0;
scoreSum = 0;
additional = 0;
}
- 12-11-2011, 02:36 AM #4
Re: Grade Book class, please help
myStudents.add(aStudent); It says that this line is null
- 12-11-2011, 02:38 AM #5
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
Re: Grade Book class, please help
in the Classlist class it says :java.lang.NullPointerException: null
Last edited by star12345645; 12-11-2011 at 02:42 AM.
- 12-11-2011, 02:46 AM #6
Similar Threads
-
Urgent help! npassing and highest grade
By aznlnja in forum New To JavaReplies: 1Last Post: 10-13-2011, 10:30 AM -
Help with calculation for final grade of student
By Braxtonmj in forum New To JavaReplies: 7Last Post: 05-10-2010, 11:49 PM -
Array highest grade
By Cdlove in forum New To JavaReplies: 5Last Post: 05-05-2010, 09:25 PM -
Grade my questions, lol
By syntrax in forum New To JavaReplies: 4Last Post: 12-16-2009, 06:03 AM -
Help with JAVA (Grade Book)
By Sara_21 in forum New To JavaReplies: 3Last Post: 11-30-2009, 02:45 PM
Bookmarks