• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Constructing classes

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.)
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tobias Hess:

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.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[B]

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic