• 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

Third Overloaded method not compiling

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Create a class named Commission that includes three variables: a double sales figure, a double commission rate, and an int commission rate. Create two overloaded methods named computeCommission (). The first method takes two double parameters representing sales and rate, multiplies them, and then displays the results. The second method takes two parameters: a double sales figure and an integer commission rate. This method must divide the commission rate figure by 100.0 before multiplying by the sales figure and displaying the commission. Supply appropriate values for the variables, and write a main () method that tests each overloaded method. Save the file as Commission.java

b. Add a third overloaded method to the Commission application you created in Exercise 1a. The third overloaded method takes a single parameter representing sales. When this method is called, the commission rate is assumed to be 7.5% and the results are displayed. To test this method, add an appropriate call in the Commission program's main () method. Save the application as Commission2.java



COMMISSION.JAVA




COMMISSION2.JAVA This is the one I am having some issues with. I am not sure if the third overload is correct. Please help. Thank you.


 
Ranch Hand
Posts: 36
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Suzie,

Welcome to the Ranch!

What error did you get? Was it a compilation error?

One thing I notice in Commission2.java is you have not tested the new overloaded method in line 10. You have put

but the new method you intend to test, accepts only 1 parameter. Besides where is 'fixedRate' initialised?

Thanks
Deepak
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you will find the methods you are being asked to write should not be static.
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, the local variables sales and fixedRate are not defined in your 3rd method. Check the case of your variables.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I'm not sure what you are trying to do with this bit of code. If fixedRate is infact a Class, then you should name it FixedRate to avoid ambiguity. Based on your method declarations, fixedRate is an int variable or a method that returns an int value? In either case, you can't use "new" for a method/variable. Also, the second statement above doesn't have any bearing on the rest of the code (even if we overlook the error that fixedRate is not a class).
 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I am still trying to correct the codes. To Deepak, these are the error messages:


Commission2.java:10: error: cannot find symbol
computeCommission(Sales, fixedRate);
^
symbol: variable fixedRate
location: class Commission2
Commission2.java:22: error: cannot find symbol
int rate = new fixedRate();
^
symbol: class fixedRate
location: class Commission2
Commission2.java:23: error: cannot find symbol
new fixedRate(0.075);
^
symbol: class fixedRate
location: class Commission2
Commission2.java:24: error: cannot find symbol
double commission = sales*(fixedRate/100);
^
symbol: variable sales
location: class Commission2
Commission2.java:24: error: cannot find symbol
double commission = sales*(fixedRate/100);
^
symbol: variable fixedRate
location: class Commission2
Commission2.java:25: error: cannot find symbol
System.out.println("Commission on sales of $ " + sales + " with a fixed rate of " + fixedRate + "% is " + commission);
^
symbol: variable sales
location: class Commission2
Commission2.java:25: error: cannot find symbol
System.out.println("Commission on sales of $ " + sales + " with a fixed rate of " + fixedRate + "% is " + commission);
^
symbol: variable fixedRate
location: class Commission2
7 errors
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, it appears you want fixedRate to be a variable; you have it declared as int, though I would think you'd want a float or double. In any of those cases, you just assign it a value instead of using "new" - int fixedRate = 7; or float fixedRate = 7.5; And the other poster is right, you aren't calling that method, currently.
 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I will go over the codes and see if I can conquer the problem. Really giving me a headache now.

 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am restarting the commission2 because the codes are still not compiling
 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Guys,

This is what I have done, please double check & see if everything is ok. The code compiled but just want to be certain that it is correct.




As you can see in the last System.out.println - I had to use the figure (10000) for Sales instead of the word Sales. It would not compile with the word.

Appreciate your revision.

Thank you

[Edit - added code tags - see UseCodeTags for details]
 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the result after it compiled:


Sales Commission: $750.0
With 7% commission rate, the commission is $700.0000000000001
With 7.5% commission rate, the commission is $750.0
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you insist on using floating-point arithmetic, what do you expect? Read FAQ no 20. Also find out about BigDecimal, which would not have given such an error.
 
Ryan Sykes
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to read up on variable scope in Java. You seem to still be confused about this. You noted that you had to replace "Sales" with 10000 to get it to compile in one of the methods, but did you understand why? Sales is not defined anywhere within the method, nor is it a static class variable, so there is no reason that the method would magically be able to know what Sales is and what value it contains.

Additionally, your variable should be named sales, not Sales as the latter would normally indicate a Class name.

Finally, if you are not comfortable with using BigDecimal yet, you can still use System.out.printf() with appropriate formatting to display the numeric values with 2 decimal places.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find an example of the use of BigDecimal here. I wouldn’t believe anything written by the author of that post, however
 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys for your insight, guidance & assistance. I got it to compile.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you get it to work?
 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I got it to compile.

Thanks again guys. Love always
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Suzie G. Brown wrote:Yes I got it to compile. . . .

That’s not what I asked.
 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about that Richie, I got it to work. Sometimes the brain is a bit slow
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done When you repeated, “I got it to compile,” I got suspicious.

And it’s not Richie. Look carefully.
 
Suzie G. Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I stand corrected Ritchie. Please accept my sincere apologies
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic