We help IT Professionals succeed at work.

# Methods, Classes, and Objects

on
Hello I have to 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.
Finally, you’ll add a third method to the previous program. This
method will use the same sales value as the previous methods,
but will calculate the commission based on afixed 7.5% rate.
The completed program with all three methods shall be saved
as Commission2.java and compiled as Commission2.class.

My attached file is what I have so far. I really want to understand java. Please help Commission.java
Comment
Watch Question

## View Solution Only

Awarded 2011
Awarded 2011

Commented:
But why did not you write all these methods in your code?

If this is a hoemowork - we cannot write program instaed of you - we can only
The snippet you posted has no methods, which you mentioned.

Attempt to write them and then we can look at them togeteher

Commented:
No I want  someone to help me learn how to write programs on my own. Don't do it for me , I just need guidance on how to successfully do this.
Awarded 2011
Awarded 2011

Commented:
so write these methods so that I could correct.
I can write the first lines for you:

public double getCommission(double sales, double commissionRate) {....}

public double getCommission(double sales, int commissionRateInPercents) {....}

public double getCommission(double sales) {...}

now write the bodies of the methods and put them in the class

Commented:
Ok I think this is alot closer but with the rate it's hard. I can't seem to get the calculations to perform correctly.

public class Commission
{
public static void main(String[] args);
{
double sales = 50000;
double commRate = 0.075;
int rate = 7; }

{
public double computeCommission double sales, double commRate;
commission = sales * commRate;
System.out.println("Commission on " + sales + "sales figure with" + commRate + "%" + "is " + commission); }

{
public double computeCommission double sales, int rate;
commission = rate/100.0;
commission = rate * sales;
System.out.println(""); }

}
Awarded 2011
Awarded 2011

Commented:
No, these don't even follow any formats of the methdos
- how shouel method be declared, where should methdo parameters be placved?
How should you separate methiod declaration from methoed body

Look at any example of any java code and make ity right

Commented:
I'm sorry i think this is the simplier way:

public double computeCommission double sales, int rate;
commission = (rate/100.0 * sales);
System.out.println(""); }
Awarded 2011
Awarded 2011
Commented:
no, no,  this syntax is wrong

read the beginning of very basic java book
or find on-line java beginner tutorial (juast paste this to google)

Commented:
This is what I have now but I'm going to read this beginners book I found so that way I can try to learn it on my own because its too difficult for me and I want to learn it without help. So thanks alot for attempting to help me. I greatly appreciate it :)

public class Commission
{

public static void main(String[] args);
{
double sales = 50000;
double commRate = 0.075;
int rate = 7; }

public double computeCommission (double sales, double commRate)
{
commission = sales * commRate;
System.out.println("Commission on " + sales + "sales figure with" + commRate + "%" + "is " + commission); }

public double computeCommission (double sales, int rate)
{
commission = (rate/100.0 * sales);
System.out.println(commission); }

public static void computeCommission (double sales)
{
commission = (sales * (int) rate);
System.println("The commission of" + sales + "with a" + rate + "is" + commission);
}
}
}

Awarded 2011
Awarded 2011

Commented:

Method which decalres return type should return value
these methods would never compile

Commented:
Ok