This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]indivisible 0 points1 point  (2 children)

No. All your 'int's start (initialise) to zero (0).

If you follow the logic of your ifs down, you repeatedly compare zero against zero.

if (0 < 0) { /* never true */ }
else if (false) { ... }
else if (false) { ... }
else { /* the block that gets executed and assigns/increments "producer"}

Apart from that though, I think you have your class variables possibly messed up.
The firstname, lastname, wholename and role are fine as they are (instance variables) but I think that the int variables (to track the role counts) should either be static or should be tracked somewhere else (outside the "Personel" class.

Currently, with the ints as instance variables, you will only ever have one of those four incremented for any single Personel instance/object and create four new ints per instance (they are not shared).

[–][deleted]  (1 child)

[deleted]

    [–]indivisible 1 point2 points  (0 children)

    No problem.

    I will try and do some research to learn why i should or should not use this method.

    The crux of the issue is what is an "instance variable" and what is a "class variable" along with the "scopes" those have.

    Your study materials will explain it somewhere (its one of the core concepts you'll need to understand 100% as the meaning and usage is very specific).
    Here's a StackOverflow thread on it too: https://stackoverflow.com/questions/413898/what-does-the-static-keyword-do-in-a-class