File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic

Need help with displaying code to console

 
kenny gill
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator


I'm trying to display a few project and quiz scores but I can't get anything to appear on the console. The console is completely empty when I try to run the code.

I'm not sure where the problem is in the code so I'd really appreciate it if someone could look over my code and see what's wrong.


Student class:




Main class:

 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Isn't this the same question you asked here ?
It's better to continue the discussion there where you've already been given an answer.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Your getProjectScoreForID method always returns empty string.
projects array is filled so that all the values are -1 (in your constructor), and in main method you didn't put any other values in it. If you check the the getProjectScoreForID method you'll see that -1 doesn't satisfy any of those if-else if conditions you have there. That's why you get no output. If you replace the last else if with just else (e.g. all scores less than 50 are graded with F, no matter if it's 0 or 49 or other value), it should probably work.

You have the same situation in your getQuizScoreForID method.

By the way, didn't you already post something similar to this? I think I've seen this class yesterday...
 
kenny gill
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator

Yes but I wanted a new thread because I've changed and added some code to the student class.

Sorry about that
 
kenny gill
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator

I've now been able to fix my code so no further help will be needed.
 
Winston Gutkowski
Bartender
Pie
Posts: 9460
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
kenny gill wrote:I'm not sure where the problem is in the code so I'd really appreciate it if someone could look over my code and see what's wrong.

Well first, could you please correct the indenting. As it stands it makes your code very hard to read.

However, a few things off the top of my head; none of which have anything to do with your problem:

1. You do like 'while' loops, don't you? Why not just use 'for' loops? They're generally much more compact and complete. And for the ones in your Student constructor, you could use Arrays.fill().
You might also want to think about providing a descriptive constant for your "doesn't have a score" value, eg:
public static final double NO_SCORE = -1.0;

2. The code at 111-125 is repeated verbatim at line 137.

3. Your checks at lines 87 and 98 basically do exactly the same thing, just with different arrays. How do you think you might make them more generic?
It's also worth noting that another alternative is not to do them at all and just let the method throw an ArrayIndexOutOfBoundsException. It's sometimes best not to mollycoddle your users too much.

5. You don't have to use 'array.length - 1' all the time. Have a think how you could modify your conditions to just use 'array.length'.

6. getProjectScoreForID(int ID) seems very low level for a public method. How is a client likely to know that Josh Bloch's Biology project is @ ID number 7?

7. getProjectsLength() and getQuizzesLength() are poor choices for method names, since they describe internal details (the length of the array) that a client really doesn't need to know about. How about projectsCompleted() and quizzesTaken()?

8. Again, getNextProjectsIndex() seems very "bits and bytes". Why not just have an addProjectScore() method, and hide all that index manipulation away from your clients?
Indeed, if those arrays were Lists instead, you could just use its add() method, and you wouldn't have to worry about any limits.

When you've corrected the indenting I'll have a look at your actual problem.

Winston
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Stuart A. Burkett wrote:Isn't this the same question you asked here ?
It's better to continue the discussion there where you've already been given an answer.
Agree. Closing this discussion.

And please, when you correct the indentation, get rid of some of the unnecessary blank lines, which also make code harder to read.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic