This is where I'm at right now. Am I on the right track? pointers on fixing whats here?
If you name is "Artemis Ehnis" then why do the JavaDoc comments state that the author is "scottjensen"
What is the purpose of these lines, is this a test case?
The code that you've provided does not run as it is, you are missing a couple of }.
You appear to be doing okay, but it's kind of hard to tell. We can tell more once you have the program doing a bit more.
I hope that you will find that there are many people well versed in Java and most of them are willing and able to help out.
Please note, that we generally do not provide full working solutions, especially in the Beginning Java area.
Instead we provide hints and code snippets so that the end user can discover the solution on their own.
To answer the snippet I was trying to make sure those variables stayed static and nothing would change them. I realize that was not the way to do that.
I have since re-written my code and have it working. My only issue is the output is lacking spaces and I don't know how to fix that.
You should not do this
but maybe you meant to do this
The double quote with nothing in it is a waste of resources, with a space surrounding by the double quote you can get some formatting.
It appears as though you supplied code snippet is missing a couple of } at the end.
In the future, please supply those so that one can copy the full code and run it. Sometimes missing a } is the source of the problem.
I can see you are running into trouble. You are mixing things in a static context and things in an instance context. Get as much out of the static context as you can. Get as much code out of the main method as you can: we can see it is already too long and you have only shown us its beginning. Look here. You have made things worse between your first post and your second by moving the fields into the main method.
Thank you for the quick responses it's allowing me to see the little things I'm missing.
Pete Letkeman wrote:
Pete's way is good, and I would recommend it. As a point of contrast, this is how I'd do it using the printf() method (print-formatted).
"%s" prints a String
"%.2f" prints a float or double with 2 decimal places
"%n" prints a new-line
Did you learn about the methods use? In case yes, you are lacking that. All code is crammed to main method without attaching any context to its separate parts.
I'm also quite disappointed to see a suggestion of formula to be used in specified requirements, which is:
(total annual sales * Commission %)+salary=total annual income
Even though for most it looks trivial, I'd say much more readable is a form of other way round:
salary + (total annual sales * Commission %) = total annual income
And more correct explanation could be:
total annual income = salary + (total annual sales * Commission %)
And that is mainly because base salary is agreed upfront, while the commission might be earned at the end of sales period and might be not. Not sure if you get an idea what I have in mind, but such way of following suggested form of formula makes program cryptic, much harder to read and much harder to understand when you introduce more parts like that.
But probably it is just an unfortunate of the given instructions.
I'm going to see if I can figure out accomplish the suggestion from @Campbell Ritchie.
@Carey Brown I can now see how that works. I spent some time last night trying to set that up I had figured out the %s for a string, but got lost in the others.
I have learned more in 1 day here than in 2 weeks of class.
Consider making the commission (3½%) a final static field, but only if it can be regarded as a constant for all workers.
In your situation, the launching class might be called MainApp which would run TotalAnnnualSalary. This might have a method called calculate and there you would use a Commission object. (Remember, an object is an instance of a class.) Where your Commission class (the file) is would depend on the size of your app, but for a little project having everything in one package is fine.
Yes I was trying to make a TotalCompensation (main) and a EmployeeSalary (run) that would do all the variables and do the math.
Just wanted to make sure the main was only the execution part and would display the output, while the run accepted the input and did all the calculations on the variables.
Now we add in a commission requirement, a bonus, and a table to show potential gains for higher sales.
I've been struggling with making mine work. I thought i had everything except for the tables and my main class, but still not sure.
I would like some feedback.
You have a method computePay() that actually does three things: Prompts for sales, computes the pay, and prints a response. I would suggest breaking these responsibilities into separate methods. It might be handy to have a couple of private fields (no getters): commissionEarned, and bonusEarned, and anualPay.
Artemis Ehnis wrote:Any suggestions on a video that walks through an actual implementation of Scanner? not just a single class? I still don't know where to put the input and how to pass it across the classes. I've tried a couple things and still no joy.
Because this Scanner issue comes up quite often, many developers create a utility class to handle this. As a utility all methods are static. Here's a bare bones one. Add this class to your project and then all your other classes can use Keyboard. To use it in your code it would be something like this:
Since Java9, it has been possible to get a Stream<String> from a Scanner too. Maybe you should enhance that by requiring a sentinel value for stopping the Stream with takeWhile().
Now I can run the project without errors, but I get no request for input and no output other than run: 0.0 build successful (total time: 0 seconds)
I believe I need to move the scanner input into the main class. Should the if else statements be in the main class as well? Would it be better to make a employee class that has a constructor for the employee and compensation class with a compensation constructor?
I really want to learn the right way, but have zero background and the material I've been given is the certificate study guide and you folks.
Thank you for feedback and patients.
If we call variables as methods in comments, that suggests that need to delete everything and start over with very small steps. And perhaps only after revising slides and class examples.
There are lots of methods but they never being called, or at least I don't see them called. Then OP mysteriously trying to access default sales field. I'm confused.
I don't think you need any keyboard utility classes here. In my opinion you need simple things which You can understand. That understanding comes when you trying in practice one or another technique without copying and pasting stuff and assuming it is OK because somebody more experienced gave you.
I also disagree with Carey here, I don't think it helps for OP to show such indentation (especially when he's a starter), at least I cannot follow it either. There are lots of stuff in that class OP doesn't need in that project, I think it just adds confusion, which is already too much in OP's head.
If OP would learn only a good indentation and formatting in this project getting lowest mark for everything else - I'd say that would be a bigger achievement than submit such work which is suspicious. Why all those getters setters if everything is meant to be printed from same class...
I have taken your advice and went back and started all over. It compiles now and works for the most part. Stuck on the if else outputs. For some reason it is only giving me my first print command and not running the rest of the process.
Looking to some of the constructs you had come up, to me seems that you've heard about Object Oriented programming. Am I right?
The thing is, that such exercise I think either needs to be solved all in one class with several methods (typical approach at the beginnin), or, if you learned about objects already - properly.
That properly means, not just to create more than one class, but to create classes which conveys exact ideas.
Now you have class Employee. But you also have some methods which are called getCompensationApp() and potentialTable() - none of them make sense to have them in Employee class.
But before I move on with my thoughts, if you could please answer how much you have learned about the objects.
I see you struggle a lot with this fairly simple exercise, and I believe you struggle not because you couldn't understand the logic, but simply because you don't understand how that logic is wired up. And that is because you assigned responsibilities incorrectly, what Employee supposed to know. Who supposed to calculate commision, etc... The success of such project depends pretty much how you design your application - and that is the whole beauty of object-oriented programming.
Which path to go, you need to tell us what kind of significance among other assignments this exercise has. Is it lab homework? Is it tutor marked assignment? Maybe final marked assignment? That way it would be easier to understand what is expected from you with this exercise and how much effort is needed.
@Knute the output at the end is an assignment requirement that after showing what the persons annual compensation is it then returns a while loop showing compensation until the sales reach 50% more than current sales. Example if you sell 100,000 it then posts an output for every 5000 until it reaches 150,000. In this case it is messed up and is outputting over and over like it was the compensation portion not a table of possible.
@Liutauras you are correct. I understand the principals of object oriented languages. I am lost with the "wiring". Every tutorial or instruction I find is great for showing the pieces. They are just really lacking on how they work together. Having a reading issue does nothing when the material you are given is the certification manual not a beginners book. These are lab homework assignments and each week builds off the last. I just really want to know java and the class isn't really teaching, they expect a very moderate return from assignments. I'm working on trying to clean this up and make it not only work, but be correct. I'm also working on the next assignment which requires 2 employees and a comparison with their salaries. As for objects and classes I understand the purpose of a constructor and I only put the potentialTable at the bottom to get the assignment turned in. Now I will fix it in it's own class when there is more time.
Artemis Ehnis wrote:@Knute the output at the end is an assignment requirement that after showing what the persons annual compensation is it then returns a while loop showing compensation until the sales reach 50% more than current sales. Example if you sell 100,000 it then posts an output for every 5000 until it reaches 150,000. In this case it is messed up and is outputting over and over like it was the compensation portion not a table of possible.
Here's what I get when I run your program:
What's the problem with this?
"Your annual compensation is x"
that part is correct.. the last piece is a potential so it would be an output of
"If your sales had been "x" you could have earned "y"
Using your example if you sold 100,000 it would output 100,000 + salary = annual salary.
Then go on to give potentials;
if you had sold "x" you would make "y"
We just got into arrays this week so I hadn't tried an arrayTable which is exactly what i wanted, but hadn't learned yet. I would have been happy with just getting the text output right and cutting off the you have earned a commission all together in the outputs after the initial return.
I'm probably not making sense right now sorry.