File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

probably doing something stupid, but results don't make sense to me

 
Gene Matthews
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first post, so hopefully I will get the code inserted/formatted where it is readable. I'm working on a class assignment; one that I didn't think I would have any problems with but I'm seeing some results that I can't figure out. I'm probably doing something dumb but I have not been able to spot it. I have two classes shown below. A Student class and a Main class (with a main method). I've got some debugging System.out.println statements inserted into the main method and into the setProjectScore() method in the Student class. I'm making a call to setProjectScore() which is setting the first element in an array to a value. However, when I return from the method call and print it out there, the value has changed (from 100 to -1).

Can anyone please tell me why the projects[0] is set to a -1??


When I run it as it exists below I get the following output:






 
Paul Mrozik
Ranch Hand
Posts: 117
Chrome Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gene,

Have a look at this:



And then your method call:



Now analyze the conditional statement more closely and you should be able to figure it out. It's the root of the problem, and not only in that function.

 
Gene Matthews
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for the nudge in the right direction. All working now. As you pointed out, I had a few instances of checking for >0 when it should have been >=0. Thanks again!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic