Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: need help creating a Commission Calculator

1. ## need help creating a Commission Calculator

I need to create a simple Java program for a commission calculator with the following requirements:
I need to ask the user to enter their total sales (as a double) in at the keyboard and I need to use "if" statements to tell them
their commission (sales * commission rate) using the following criteria:
o < \$8000 in sales – Commission rate = 10%
o \$8000 to \$12000 in sales – Commission rate = 12%
o \$12000.01 to \$18000 in sales – Commission rate = 15%
o \$18000.01 to \$20000 in sales – Commission rate = 18%
o > \$20000 in sales – Commission rate = 20%
Then for the output the user’s Commission in a well formatted way (use the DecimalFormat class)
In comment blocks have a description of what the program does. thank you! I think I did something wrong here is mine
```import java.util.Scanner;

public class CommissionCalculator
//This program calculates the commission of sales
{
public static void main(Strings[] args)
{
// create a scanner
Scanner input = new Scanner(System.in);
//define variable
double sales;   //inputted sales amount
double commission = 0; //commission pay amount

double sales = input.nextDouble();

if (sales > 20000.01 )

commission = sales * .20;

else if (sales > 18000.01 && sales <= 20000)

commission = sales * .18;

else if (sales > 12000.01 && sales <= 18000)

commission = sales * .15;

else if (sales > 8000.01 && sales <= 12000)

commission = sales * .12;

else (sales <= 8000)

commission = sales * .10;

{
}

}```

2. ## Re: need help creating a Commission Calculator

Hi, Welcome to the forum! Please read Announcements - What's Wrong With My Code? for guidlines on how to code
I think I did something wrong here is mine
so what is wrong?

3. ## Re: need help creating a Commission Calculator

public static void main(Strings[] args)
the argument should be String[] args not Strings[]

else (sales <= 8000)
you don't have to put condition in else keyword.
the program will read the statements in else when the if and else if condition falls to false.

if (sales > 20000.01 )

commission = sales * .20;

else if (sales > 18000.01 && sales <= 20000)

commission = sales * .18;

else if (sales > 12000.01 && sales <= 18000)

commission = sales * .15;

else if (sales > 8000.01 && sales <= 12000)

commission = sales * .12;

else (sales <= 8000)

commission = sales * .10;
please don't put carriage return every after conditional statement since you are not using braces,
and please, use braces every conditional statement.

{