![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Location: Charleston, SC
Posts: 11
Rep Power: 0
![]() |
commission rate
I need to modify this to show one commission rate if under a certain $ ammount and a higher commission for over that number...I can't seem to figure out where to look it up. I am very new to this language, all programming.... I am not loking for you to do it for me but rather give me some direction....
Here it is one of my two attempts: public class Commission2 { public static void main(String[] args) { double sales = 50000.0; double commission = 0.0; double rate = .075; commission = sales * rate; System.out.println("Commission on sales of " + sales + " with a rate of " + rate + "%" + " is " + commission); } public static double computeCommission(double s, double r) { return (( (double) r / 100.0) * s); } public static void computeCommission(double sales, int rateTwo) { double commission, rateAsPercent; rateAsPercent = rateTwo / 100.0; commission = sales * rateAsPercent; System.out.println("Your second commission is " + commission); ) } or public class Commission3 { //main() sends the values to each of the methods public static void main(String[] args) { double salesFigure = 10000.00; double commRateOne = 0.05; double commRateTwo = 0.075; computeCommission(salesFigure,commRateOne); computeCommission(salesFigure,commRateTwo); } //First computeCommission() computes the two double variables public static void computeCommission(double sales, double rateOne) { double commission; commission = sales * rateOne; System.out.println("Your first commission is " + commission); } public static void computeCommission(double sales, int rateTwo) { double commission, rateAsPercent; rateAsPercent = rateTwo / 100.0; commission = sales * rateAsPercent; System.out.println("Your second commission is " + commission); } } |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Lets take your second example. First, the second method should be :
public static void computeCommission2(double sales, double rateTwo). You can't have 2 methods with the same name. Now in main you should have something like : if(salesFigure<=25000)computeCommission(salesFigure,commRateOne); else computeCommission2(salesFigure,commRateTwo);
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#3 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Actually, I think that it should be okay if he has the same method names as long as he has seperate argument types. That's just an overloaded method, unless I'm missing something.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#4 |
|
Professional Programmer
|
It would have been ok, but if he had something like :
computeCommission(double,double) and computeCommission(double,int) or some other combination. Here, the commRateOne and commRateTwo, are both double, and you cand have : computeCommission(double,double) and computeCommission(double,double).
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#5 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
I don't understand why that would cause a problem, though. Since commRateOne and commRateTwo are just being passed to the method, wouldn't that just invoke the first method twice, and never call the computeCommision(double, int)?
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#6 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Ohh. Damn it. I didn't entirely read your first post, Xavier. I understand what you're saying. My appologies.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#7 |
|
Professional Programmer
|
no problem dude
![]()
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#8 |
|
Newbie
Join Date: May 2005
Location: Charleston, SC
Posts: 11
Rep Power: 0
![]() |
you guys are good I will try this and thanks again...
greg |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|