• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing error  RSS feed

 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am compiling this program and it prints []



Please help me understand why...
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're printing the result of this code:



To me that says the List returned by the getEligableCandidates method is empty. From your post it sounds like you didn't expect that. So I would examine the code in that method to see why it's returning an empty List.
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So after I looked at that method:

That if-statement which decides whether to add a Candidate to the list is devilish hard to read -- you might want to reformat it a bit so it's easier to understand. However at the very least it looks like it should add candidates whose grade is 85 or higher, along with maybe some others. But it doesn't add any candidates at all. Therefore there aren't any candidates whose grade is 85 or higher.

Based on your code which creates the Candidates, you would think that several of them have grades of 85 and higher. But they don't. So how did that happen?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, it looks like the getGrade() method is returning a number less than 85 for every Candidate. What's up with that? Well, it returns the grade variable so that variable must not be set correctly. So where is it set? The setGrade() method sets it. But you aren't calling setGrade(). You're expecting the constructor to set it... Aha. Your problem is line 16.
 
Campbell Ritchie
Marshal
Posts: 56522
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing: I can see multiple String literals saying things like excellent and poor. That looks like one of the many things Strings are no good for. It looks to me like a candidate for an enumerated type. You want something like this:-As you will see from the tutorials link, you can add fields and methods to those constants; they are after all full‑blown objects.
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code doesn't set the fields innovation, grade, regulation, or communication.  That could be your problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!