I would change that. Same idea, same result, two unnecessary lines gone.Alan Anderson wrote: . . .
. . .
Alan Anderson wrote:Here is a copy of the responses at command line and the results i get...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Alan Anderson wrote:Here is a copy of the responses at command line and the results i get...
I hate to say, but I wouldn't use toString() at all for this sort of thing.
toString() is generally used for debugging or very basic display, whereas what you want is a report with very specific formatting.
Campbell Ritchie wrote:
Alan Anderson wrote: . . .
[code=java] @Override
So where are you getting the odd marks? Put some print statements into the class which contains those marks. At the end of every method in that class simply write System.out.printf("xyz() method: mark = %d%n", mark);//test or similar. You can search for //test later and remove or comment out your testing code. Then you can watch the values change, and see where they change. And then you can work out where you are doing any adding, and whether you are adding the same thing twice and doubling up your results.
I got your suggestion up until this point...i do not understand this paragraph
Alan Anderson wrote:what do you suggest i use? Am basically following the design pattern we use in class (not that i think it's flawless though)
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Junilu Lacar wrote:Apart from the strange use and implementation of toString(), the design of the classes has much to be desired. Both the Exam and Student classes have instance variables that track numberOfStudents. The responsibility of tracking the total number of students does not belong in either of these classes and the duplication and misplacement of this information is at the heart the problem you're seeing.
Edit: I just noticed that the duplication extends into the Teacher class as well, which again is an inappropriate assignment of responsibility, IMO.
Alan Anderson wrote:What would you do? you grand masters are only pushing in the dagger at the back of my head deeper and deeper...how do i pull it out?
Teacher, what did Campbell get in Java Programming?
Can I have a look at the Java exam results, please? I would like to know whether I got more than Campbell.
What did you get in Java Programming, Campbell?
Campbell Ritchie wrote:
Does a mark belong to the student, the module, the teacher, the exam or what?
Alan Anderson wrote:The original code is quite large,this one is just to test the problem i was having
Junilu Lacar wrote:BTW, I don't agree with the design as specified. In particular, "A Student has a Result" does not sit well with me. I would rather have the Module track the students enrolled in that module and each student's result for that module as well. That is, a module "knows" what students are taking it and what each student's result is for that module.
Alan Anderson wrote:No, the Exam and Teacher classes are names i gave to the Result and Module classes respectively.