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.

 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);

 }

 }

Recommended Answers

All 6 Replies

What errors do you get? Does the program compile, run? Do you get the desired results?

if i put int= .075 which would be 7.5% it says possible loss of precision
found:double
required int:int
int rate=.075
^

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.

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

Write a method that computes the commission. The header of the method is as follows:
public static double computeCommission (double salesAmount)

Write a test program that displays the following table:

Sales Amount Commission

10000 900.0
15000 1500.0
20000 2100.0
25000 2700.0
30000 3300.0
35000 3900.0
40000 4500.0
45000 5100.0
50000 5700.0
55000 6300.0
60000 6900.0
65000 7500.0
70000 8100.0
75000 8700.0
80000 9300.0
85000 9900.0
90000 10500.0
95000 11100.0
100000 11700.0

Write a program using a For loop that will calculate the sum of every third integer,
beginning with x being 2( i.e. calculate the sum of 2 + 5 + 8 …..), for all the values of
x that are less than 100. The program will then display the result of the sum.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.