Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Constructing classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Constructing classes" Watch "Constructing classes" New topic
Author

Constructing classes

Norman Neaderhiser
Greenhorn

Joined: Mar 10, 2004
Posts: 6
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 ]
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
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
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.)


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

[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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructing classes
 
Similar Threads
Question regarding Cloneable interface and Subclasses
array being overwritten
Set Duplicates
Set Duplicates
Help with an Inheritance issue