I am working on some homework for my Java class, and I seem to have hit a few bumps in the road, possibly due to some logical errors. The project involves reading and writing student data to a text file, and storing the student data in an array. I have quite a bit of the code written, but I am having a hard time with one particular part. I need to scan through all of the student records from the text file, and return all of the student objects who are Grad Students. The idea I had for this was to use a for loop to cycle through all of the students (stored in an array), and add every grad student to another array using an if statement such as:
Code:
public static Student[] gradStudents(Student[] students)
{
Student[] gradStudents = new Student[LIMIT];
for (int i=0; i < numberOfStudentsInArray(students); i++)
{
if (students[i].getMajor() = "G")
{
gradStudents += this;
}
}
return gradStudents;
}
The problem is that I am getting errors that I have never seen before, such as:
Code:
Compiling 1 source file to /home/brendon/Documents/csci 1250/workspace/processStudents/build/classes
/home/brendon/Documents/csci 1250/workspace/processStudents/src/ProcessStudents.java:176: unexpected type
required: variable
found : value
if (students[i].getMajor() = 'G')
/home/brendon/Documents/csci 1250/workspace/processStudents/src/ProcessStudents.java:178: non-static variable this cannot be referenced from a static context
gradStudents += this;
/home/brendon/Documents/csci 1250/workspace/processStudents/src/ProcessStudents.java:178: operator + cannot be applied to Student[],ProcessStudents
gradStudents += this;
3 errors
BUILD FAILED (total time: 1 second)
I am not looking for someone to do my homework for me, but rather to give me a gentle nudge in the right direction. We barely covered arrays in class, so I am sure that I could be missing some important piece of information. Thanks so much!!
Bookmarks