*
The moose likes Beginning Java and the fly likes probably doing something stupid, but results don't make sense to me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "probably doing something stupid, but results don Watch "probably doing something stupid, but results don New topic
Author

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

Gene Matthews
Greenhorn

Joined: Feb 17, 2013
Posts: 2
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

Joined: Feb 10, 2013
Posts: 117

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

Joined: Feb 17, 2013
Posts: 2
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
 
subject: probably doing something stupid, but results don't make sense to me
 
Similar Threads
Need help with displaying code to console
My main class will not display my code
In need of much help with my main method.
Could someone explain what is wrong with my set methods?
I'm trying to run my code through console but the option is not available