User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,705 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,241 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 201 | Replies: 4 | Solved
Reply
Join Date: Feb 2008
Posts: 28
Reputation: zwench is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
zwench zwench is offline Offline
Light Poster

Calculating Commission

  #1  
Jul 2nd, 2008
I want to know if this is correct for what they are asking. If I try to put 7.5% in the int= spot it errors. I am a newbie who doesn't quite understand it all.

The commission rate in the firstmethod will be entered as a decimal value (for example,
a 7.5% rate will be entered as 0.075).A second method will be included that takes the same salesvalue as the first method, but has the commission rate entered as an integer (for example, 7 would be entered for 7%.). This commission value is then divided by 100.0, the
sales figure is multiplied by the result of that calculation,and the final result is displayed to the user.


[code]

public class Commission
{

public static void main(String[] args)

{

double sales = 45000.0;
double commission = 0.0;
int rate = 5;
commission = computeCommission(sales, rate);
System.out.println("Commission on sales of "
+ sales
+ " with a rate of " + rate + "%"
+ " is "
+ commission);
double drate = 7.5;
commission = computeCommission(sales, drate);
System.out.println("Commission on sales of "
+ sales
+ " with a rate of " + drate + "%"
+ " is "
+ commission);

}

public static double computeCommission(double s, double r)
{

return (( (double) r / 100.0) * s);

}

public static double computeCommission(double s, int r)

{

return (( (double) r / 100.0) * s);

}

}

[/code}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: Greece
Posts: 437
Reputation: javaAddict is on a distinguished road 
Rep Power: 1
Solved Threads: 43
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Pro in Training

Re: Calculating Commission

  #2  
Jul 2nd, 2008
What errors do you get? Does the program compile, run? Do you get the desired results?
I AM the 12th CYLON
Reply With Quote  
Join Date: Feb 2008
Posts: 28
Reputation: zwench is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
zwench zwench is offline Offline
Light Poster

Re: Calculating Commission

  #3  
Jul 2nd, 2008
if i put int= .075 which would be 7.5% it says possible loss of precision
found:double
required int:int
int rate=.075
^
Reply With Quote  
Join Date: Dec 2007
Location: Greece
Posts: 437
Reputation: javaAddict is on a distinguished road 
Rep Power: 1
Solved Threads: 43
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Pro in Training

Re: Calculating Commission

  #4  
Jul 2nd, 2008
You say that the rate argument in any version of your computeCommission is measured in % .

Since in both cases you divide the input by 100 means that you assume if you
input 3 you mean 3% --> 0.03
input 3.0 you mean 3.0% --> 0.03
input 4.5 you mean 4.5% --> 0.045

So if you want the rate to be 0.45 (45/100 --> 45%) then the input should be:
computeCommission(double s, 45) or computeCommission(double s, 45.00)

So if you want the rate to be 0.06 (6/100 --> 6%) then the input should be:
computeCommission(double s, 6) or computeCommission(double s, 6.00)

So if you want the rate to be 0.053 (5.3/100 --> 5.3%) then the input should be:
computeCommission(double s, 5.3)

You say:
if i put int= .075 which would be 7.5%
If you want 7.5% (0.075) then you should input: computeCommission(double s, 7.5)

You get the error because int rate is an int variable and you cannot store non integer values. In int rate you must put only ints. If you do int rate=0.99999, the the rate will have value 0 in the end.
I AM the 12th CYLON
Reply With Quote  
Join Date: Feb 2008
Posts: 28
Reputation: zwench is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
zwench zwench is offline Offline
Light Poster

Re: Calculating Commission

  #5  
Jul 2nd, 2008
Thanks for that info. I will try it and let you know if it works. That makes more sense to me than this book...lol
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 2:51 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC