Originally Posted by
curmudgeon
It's not as easy as you think, trying to understand someone else's creation. I hope that you continue to progress in your programming abilities and start helping others on this and other sites and you'll see what I mean. You'll also see how much fun and satisfying it can be.
One thing that confuses me is that in my mind something this basic, getting a single input from the user, can be done by a simple method of Pay rather than creating a whole other class, EmpChoice, whose only job is to hold a static method. So why this design decision? Will EmpChoice have other tasks? Will it have state (fields)?
So this input will be obtained from within Pay as opposed to the class to obtain a single number. Again this division seems a bit arbitrary.
Based on your description EmpChoice will have nothing but a single static method, say called getCommissionChartCount(), that it will use a Scanner to prompt the user for input and will return an int for Pay to use. If you did it this way, you'd call the method off of the EmpChoice class, something like,
// inside Pay
int commissionChartCount = EmpChoice.getCommissionChartCount();
Again, I would make this a non-static method in the Pay class (or it could be static if all Pay code is in static methods) and not a separate class, but either way would work.
It would seem to me that a better class to create would be one called Employee that gets the salary and commission information and is able to calculate pay based on this.
"One thing that confuses me is that in my mind something this basic, getting a single input from the user, can be done by a simple method of Pay rather than creating a whole other class, EmpChoice, whose only job is to hold a static method. So why this design decision? Will EmpChoice have other tasks? Will it have state?"
I need to break this up into three separate files, because the main class file, Pay will be secured once it is implemented, and I will not have access to it for revisions due to my somewhat low security rating here. I am well aware that all of this can be completed in a single program file, but I need to have three files for this project....
"Again, I would make this a non-static method in the Pay class (or it could be static if all Pay code is in static methods) and not a separate class, but either way would work."
I will go back and have another look at Pay, and see if I have classes or methods created as static, but I have to say that it seems to say "Trying to access static from non-static" even if I have nothing declared as static anywhere, like here
static.JPG which is warning me about accessing a static from my main, but as you can see my main is also static??
"Based on your description EmpChoice will have nothing but a single static method, say called getCommissionChartCount(), that it will use a Scanner to prompt the user for input and will return an int for Pay to use. If you did it this way, you'd call the method off of the EmpChoice class, something like,"
Yes EmpChoice does only return a single user inputted int value, but as I said this is a three part project, so I had to make a whole new class just for that....
Anyway, thanks for all the tips, and since this is still a work in progress, I will take everything you have suggested and try to work it in to what I am trying to complete here!!