This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hello guys, I have a program that creates an object that uses the parameters and methods from another class. I am having trouble with the Bonus program recognizing one of the methods from the first class. Here is my code so far. Thanks for any advice NN
I then have a test program that displays the employee's name their pay and calculates the contribution; Here is the second class that builds upon the first:
My problem is that when I compile this I receive a message that the calContribution cannot be recognized. I also have three levels of rank and am not sure how to incorporate them so that my formula will work. Any help would be appreciated. [ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ April 20, 2004: Message edited by: Dirk Schreckmann ]
Consider the following line of code: double calBonus= (.1*contrib.getPay()-contrib.getcalContribution())*rank); You haven't declared any method named getcalContribution() in Contribution class instead it is "calContribution" May be this is the problem
Originally posted by Norman Neaderhiser: My problem is that when I compile this I receive a message that the calContribution cannot be recognized.
That compiler error is incongruous with the code you've posted. Using the code you've posted, the compiler should be complaining that it cannot recognize the symbol method getcalContribution in your calBonus method, and that's probably due to your naming the method calContribution in the Contribution class. (In other words, follow Ali's suggestion above.) After you fix that naming mismatch, you've two more problems in the calBonus method. Can you figure them out? (Big Hints: You've an extra closing parenthesis, and you don't have a return statement.)
This looks like pascal. In Java you cannot assing a value to the functionname. Instead you should make a local variable, often called ret, assign to it, and return it at the end. Another way is to write return and directly after this the computation. I think an example is in order:
I don't know Pascal, but this code looks like perfectly fine Java. A local variable is being used to store the results of a calculation, it just happens to have the same name as the method name. There's nothing wrong with that from the compiler's viewpoint.
And as a sidenote on style, the comment should look like this: /** * Comment goes here */
There's nothing wrong with the original comment style used by Norman. The JavaDoc tool will be perfectly happy with it. In fact, it's the same style of comment as required by the JavaRanch Programming Style Guide.
I don't know Pascal, but this code looks like perfectly fine Java. A local variable is being used to store the results of a calculation, it just happens to have the same name as the method name. There's nothing wrong with that from the compiler's viewpoint. [/B] Except, of course, that the compiler will complain that there is no return value for the method. It's supposed to return a double, but nothing is being returned. A return calBonus; line is needed.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.