This is backwards. You want setGrades to set the fields on your class to the values passed in the parameters. The way you have written this method, the parameters will be re-assigned to the values already stored in the fields, and then thrown away. Note that the t1, t2 and f in this method are not the fields you declared in the class.

That way you don't need to worry about forgetting to initialize fields, or initializing them differently in different constructors. Your other getters and setters are OK.

Code:

private void doAverage()
{
average = (test1+ test2+ finalExam)/3;
}

First of all, you need to divide by 3.0 rather than 3, or else you'll get an int result rather than a double. But where do you call doAverage() anyway? If you're going to store your average as a field, then you should re-compute it every time one of its inputs changes. That means add a doAverage() call to your test1, test2 and finalExam setters. Or another strategy is to not store it as a field at all, and simply compute it in your getAverage() method. So instead of this:

Three problems with this code:
1) Your actual class fields are not t1, t2 and f, but test1, test2 and finalExam. You have your assignments backward, as I pointed out in your original code.
2) You should be doing this validation in your individual setter methods, then calling those setter methods from this method.

What are those last four instance variables -- t, t1, t2 and f -- for? I anticipate the answer "my code won't compile unless I have them there!" to which I answer, if the code won't compile without those instance variables, the code is wrong. Get rid of those instance variables, and fix the code.

Do that much first, post your code again, and we'll take the next step.

Quote:

Originally Posted by johnjacob

here is what I have for my tester and for some reason student1 values are carrying over to student2