Welcome to MekTrix 4.0

Aka Shish’s Place of Stuff

I weep for compsci

I don’t even weep softly. I weep fucking hardcore. I have to wait for these people to catch up before the interesting stuff starts :(

For reference, the full question:

You have an ArrayList called “library” which holds some Book objects. The Book object has a method called getTitle() which returns a String. Write a for-each loop (which we’d been learning about in the lesson) to print the titles of each book, one per line.

And the answers:

  • for(Book title : library) {System.out.println(title);}
  • Shouldn’t the title be of type String, rather than Book?
  • Replace “title” with “book”
  • The print line should have book.getTitle() in it
  • Actually, use the “String title” in the loop, then print book.getTitle(title)
  • No no, the book already has the title, you want library.getTitle(title) !

The lecturer (a temporary one) was encouraging them with things like “that’s sort of right”, whereas the regular guy would just have said “no”…

And then as I’m walking out of the lecture, a cocky voice from behind me — “ha, they all fail – it says one title per line, and they all forgot to put +”\n” in the println command”

;___;


Leave a Reply