•
•
•
•
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
![]() |
•
•
Join Date: Feb 2008
Posts: 28
Reputation:
Rep Power: 1
Solved Threads: 0
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}
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}
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 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.
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%
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
Similar Threads
- Homework help (C)
- Help on C++ Final Exam !!! (C++)
- Simple while loop in c++ (C++)
Other Threads in the Java Forum
- Previous Thread: jabber Instant messaging
- Next Thread: sending and retrieving password


Linear Mode