Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 14th, 2005, 7:45 PM   #1
boatn19
Newbie
 
Join Date: May 2005
Location: Charleston, SC
Posts: 11
Rep Power: 0 boatn19 is on a distinguished road
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);
}
}
boatn19 is offline   Reply With Quote
Old May 14th, 2005, 11:44 PM   #2
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
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);
25000 is just an example .
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old May 15th, 2005, 12:19 AM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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.
__________________
&quot;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.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old May 15th, 2005, 12:31 AM   #4
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
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 !
xavier is offline   Reply With Quote
Old May 15th, 2005, 12:44 AM   #5
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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)?
__________________
&quot;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.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old May 15th, 2005, 12:45 AM   #6
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Ohh. Damn it. I didn't entirely read your first post, Xavier. I understand what you're saying. My appologies.
__________________
&quot;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.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old May 15th, 2005, 12:11 PM   #7
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
no problem dude
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old May 15th, 2005, 9:55 PM   #8
boatn19
Newbie
 
Join Date: May 2005
Location: Charleston, SC
Posts: 11
Rep Power: 0 boatn19 is on a distinguished road
you guys are good I will try this and thanks again...
greg
boatn19 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC