> 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);
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
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)
}
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
I too have having trouble can you help me
You need to show what you have done already :)
crunchie
Most Valuable Poster
20,095 posts since Feb 2004
Reputation Points: 1,142
Solved Threads: 985