• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Method getHeadCountElement always returns a zero  RSS feed

 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First code block is from a jUnit test
The tests in lines 64-68 fail any time the expected value should be a 1
so my code getHeadCount is not working.

I have a Headcount class that is shown in the 2nd code3 block and then OnPlanUserModule code in the last code block

The headCount is computed in lines 60-69

In NetBeans I put a breakpoint in 59 but it was not reached.


So for some reason the getheadCountElement is always returnsa a zero

Not sure what I am doing wrong. Any thoughts?  Thank you.



ount.getHeadCountElement(4,0));
        [/code]

Headcount code


OnPlanUserModule

 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I see the issue. My OnPlanUserModule class returns emplyees which I am not interested in.

I assumed that the code in lines 60-74 would output values that could be retrieved by my test program. This doesn't seem to be working.

So how do I gain access to the headcount and salary values that are being computed.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your OnPlanUserModule class, in the ProcessEmployees() method, line 45, you are creating a local variable headcount.  Since it's local, it cannot be accessed outside of the method.  To do that you need to either return the value (which means you couldn't return the employees reference) or you need to make headcount a field of OnPlanUserModule and write a getter for this field.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:In your OnPlanUserModule class, in the ProcessEmployees() method, line 45, you are creating a local variable headcount.  Since it's local, it cannot be accessed outside of the method.  To do that you need to either return the value (which means you couldn't return the employees reference) or you need to make headcount a field of OnPlanUserModule and write a getter for this field.


Knute-thank you for responding

Revised code per your comments but still getting same error. So Im still missing something.

 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
added 'this' on lines 74 and 81 but stu=ill same failure
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute thank you very much for your help. There were a bunch  more errors in the code but with  your push in the right direction I was able to get them sorted out.

Below is my final code



and revised test code

 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Congratulations on getting your program sorted, and thanks for posting your code here!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!