• Post Reply Bookmark Topic Watch Topic
  • New Topic

What am I doing here wrong?  RSS feed

 
michael solovyov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The initial output of the texfile is this. NO ARRAYLIST OR COMPARATOR IS ALLOWED:


The collateExams method collates/sorts exam objects starting with the first 'm' (midterm) of the first object and immediately followed by the same person's 'f'(final). Only a SINGLE loop construct is allowed. The output from collateExams() should be the one below but my code is not working, i.e. collateExams method is not working. Could smb help me with that? The output from collateExams() should be





 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell us what errors you are encountering in the collateExams() method?
 
michael solovyov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



And the line is


 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the collateExams method you are just initializing the r array using the following line of code Exam[] r = new Exam[exams.length]; , but you are not initializing the elements of the array. So unless you do that any invocation using r will result in a NullPointerException. Also please try to use meaningful variable names so that their purpose can be easily understood.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I shall try breaking some of those long lines which make the code more difficult to read, and you can see how it is done. You can usually do it yourself much better than I do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!