Hi ,
//In this project, you’ll create a program that calculates a salesperson’s commissions using double-precision values,
and displays the results. The commission rate in the first
method will be entered as a decimal value (for example,
a 7.5% rate will be entered as 0.075).

I read javaAddict reply here : http://www.daniweb.com/forums/thread132264.html for the same school project I have.
The reply das not explaine how you can input 0.075 which is decimal value in the "int rate = ?; whitout errors

//In this project, you’ll create a program that calculates a
salesperson’s commissions using double-precision values,
and displays the results. The commission rate in the first
method will be entered as a decimal value (for example,
a 7.5% rate will be entered as 0.075).

public class Commission {
public static void main(String[] args){
double sales = 30000.0;
double commission = 0.0;
int rate = 0.075;commission = computeCommission(sales, rate);
System.out.println("Commission on sales of "
+ sales
+ " with a rate of " + rate + "%"
+ " is "
+ commission);
double drate = 7;
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);
}
}

// How will I able enter the 0.075 in the int rate = 0.075; without error being generated?

Please if you have knowlige how it works can you help me?
Thank you
Hanz

Hello,

You cant set decimal values in int type variables.

You have to use double or float type.

Regards,

Can you be more specific please .
I know that int data type store/hold integers or whole numbers.

Project scenario!
In this project, you’ll create a program that calculates a
salesperson’s commissions using double-precision values,
and displays the results. The commission rate in the first
method 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 sales
value 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.
These two methods will be saved as Commission.java, and
compiled as Commission.class.

am trying to customize this code

public class Commission {
    public static void main(String[] args){
        double sales = 30000.0;
        double commission = 0.0;
        int rate = 0.075;
        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);
    }
}

Enyone please?
Thank you

> Can you be more specific please .
> I know that int data type store/hold integers or whole numbers.

It's pretty simple; you just need to create two methods which have different contracts defined as part of the problem definition. One takes in a double precision number of the form x/100 [e.g. 0.07 for 7%] and the other takes in an integer of the form x [e.g. 7 for 7%]. Some test invocations would look like this:

double comPct = 0.07;
double comm = compute(salary, comPct);
int comInt = 7;
comm = compute(salary, comInt);

Hi sos,
I try that and what happened is that the way you put it, it only calculate 0.07% and not 7% so I change to :

double comPct = 0.07;
double comm = compute(salary, comPct * 100);
int comInt = 7;
comm = compute(salary, comInt);

And it works without errors. What you think?

Thank you

Don't change the contract specified in the problem statement; don't change the invocation; change the logic which resides in the overloaded methods.

// Error handling and input sanity checking left out for
// brevity
public static void main(String[] args) {
  double salary = 10000.0;
  String str = /* accept the commission in double format */;
  double comPct = Double.valueOf(str);
  double com = compute(salary, comPct);
  
  str = /* accept commission in integer format */;  
  int comInt = Integer.valueOf(str);
  com = compute(salary, comInt);
}

public double compute(double salary, double comPct) {
  return salary * comPct;  // e.g. 10,000 x 0.07
}

public double compute(double salary, int comInt) {
  return salary * (comInt / 100.0); // e.g. 1000 x (7/100.0)
}

I too have having trouble can you help me

I too have having trouble can you help me

You need to show what you have done already :)

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.