You also have badly‑indented code in the first block, which will confuse you about what the code is doing. You will have to go through the code; you have so many poorly‑named variables and 0s floating around, it is not obvious how much of the code will actually run. I can see some if blocks which will not be entered.
You have a method in your TheBonus class nameds
When you use calculate1.computeBonus(); in you main method you are calling the computeBonus from the Employees class.
To call the computeBonus from TheBonus call you would use either
What do you mean by this, sorry I dont understand.
Please note that you are currently not using the recommended style guide and you are missing getters and setters as well.
What is the recommended style guide? Which getters and setters am I missing?
Thank you again for your help so far
Ryan Gordon wrote:Which getters and setters am I missing?
You do not appear to have any getters or setters for your class and everything is "public".
This may work, but it is not recommenced.
Setters and getters allow to you encapsulate your object/class.
You make object variables private and you wrap public methods around them to set and get the values.
Here is a link explaining them in detail:
Here is an example of simple getters and setters, which do not use your code:
More logic could/should be added to verify values. For instance right now age can be negative and the name values can be null.
With this Person object I could then do something like:
You can put whatever complex logic you want in your object. This sample one is only adding two strings together using the getFullName method.
Given this example your could rewrite your code to eliminate one of your Employee classes.
Ryan Gordon wrote:What are the values of cmnt and qs when you pass them into the function?
What do you mean by this, sorry I dont understand.
When you are calling a method, for instance
you are supplying values to that method. Both cmnt and qs should have values by the time you call computeBonus(cmnt, qs).
If either cmnt or qs do not have values when you call your computeBonus(cmnt, qs) then you could run into problems.
It depends on how you have setup the computeBonus method. If this method does not check for valid values then you will get errors.
Ryan Gordon wrote:What is the recommended style guide?
There is more then one style guide, some more complex/complete then others. The big things are:
If you Google for "simplified java style guide" you can find more then one however, the five basic rules listed above should be enough for beginners.
I then run into this error, is using an array in get/set not allowed or is it something else?
By the way thank you for all your help so far, I am learning and i appreciate that.
Look at the first line: the unwary reader could get the impression that "qs" is a double variable. But it isn't... it's a double variable. So it's better to declare it so it actually looks like one:
Likewise it looks like you're passing a double value to the setqs method; but you aren't, you're passing a double value. So better code:
And the third fragment: are you returning a double value? Having read my comments about the first two fragments, you should be able to answer that.
Where is the variable qs which you are getting the compiler errors about?
If you are passing four ints, what is the method supposed to receive as a parameter? Remember, you wrote the method, so you decided what parameters it would take. Did you declare it as double or double...?
You can be close to being done
Here is a start
This line Emp1.setqs(5000, 7000, 4000, 8000); is expecting an array and you are not providing an array. You are providing four different values.
This line Emp1.setbonus(qs * .03); is expecting a value for "qs". But you have not defined a variable qs inside of the main function.
If qs is an array then you cannot simply multiply an array by a value. You have to multiply each element of the array by that value.
Are you able to paste all your code in your response so that we can see what exactly you have now?
that is not how you create an array, wrong brackets, missing "new" and that is not now you pass a value to the setqs method. You are missing brackets.
This is a bit better
You cannot multiply an array like that. You have to multiply all of the elements of the array by the value.
I would put this multiplying logic inside of the Employee class.
Once you have the figured out then you should be almost done.
I tried adding the math login in the top of employee class
and i get
All the stuff that both of you explained to me is making sense, but arrays are really causing me problems, thank you again for all your help so far I appreciate it.
Ryan Gordon wrote:How do you multiply the elements of the array by the value?
This page https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html talks about and shows using the for loop to get the elements of the array.
Then you need to multiply those values.
What if you do this:
quarterlysavings.length is the number of elements in the array.
j is the index of the array element
quarterlysavings[j] is the individual array element
If you do your loop like that then you do not have to change the loop if the size of the array changes.
Here is your code with the spacing fixed:
If you replace
you will not get that error any more.
Or you could wrap this up in a method all by itself kind of like
This line of code
probably does not do what you want it to.
"getProperty" and "setProperty" generally are used for the private variables of the class like firstName and lastName.
There are times when you can combine two properties to make a third property like fullName.
When you have a method which calculates a value you could use something like
Or something like
A property is a the value of something at a point in time. For instance a the color could be a property of eyes and it's value could be blue.
This value could possibly change from object to object.
A method could be used to calculate a value.
For instance a method could be used to calculate the total area of a triangle. This could change depending on the properties and it's calculated differently for a triangle and a rectangle.
If you need to calculate something using decision statements or loops or by checking the value of one or more property then you most likely want a method and not a getter or a setter.
The error that you are currently getting states that the variable getCommitment is not part of the Emp1 object. Emp1 is an instance of the Employee class.
Do you have a variable named getCommitment or do you have a method named getCommitment in the Employee class?
If you have a method named getCommitment then you need to call that method with the correct brackets, possibly like
One: We know that we need an class to handle some employee information
Two: We need to sum up the yearly savings
Three: We need to calculate the bonus based off of quarterly savings and a min value and a percentage
Four: We need to test out the code to see if it works
You have already completed part 1 in one or more of the previous postings in this thread.
You have the formulas for both part 2 and part 3
Part 4 shows you how you can test your object out in the same class.
As is this code runs, but you still need to complete it. I suggest completing one part at a time and testing it.
I would suspect that some/most of this has been covered in a textbook or during class if this is indeed a homework assignment.
You will need to change/remove all of the return statements as they are there only to make the program run
This currently outputs something like this
when these two commands are run
I hope this helps put you on the correct path.