The problem
You have just started a sales job in a department store. Your pay consists of a base salary and a commission. The base salary is $5,000. The scheme shown below is used to determine the commission rate.
Sales Amount Commission Rate
$0.01–$5,000 8 percent
$5,000.01–$10,000 10 percent
$10,000.01 and above 12 percent
Your goal is to earn $30,000 a year. Write a program that finds out the minimum number of sales you have to generate in order to make $30,000.
Breaking it down
private static double SALE_BREAKING_POINT = 30000.0;
private static double BASE_SALARY = 5000.0;
private static double MINUS_BASE = SALE_BREAKING_POINT - BASE_SALARY;
public static void main(String[] strings) {
double commission = 5000.00 * .08;
commission += 10000 * .10;
double salesAmount = 10000.01;
do {
salesAmount += 0.01;
commission = salesAmount * 0.12;
} while (commission < MINUS_BASE);
System.out.println("You need $" + salesAmount
- " sales amount to make a commission of + "
- SALE_BREAKING_POINT);
}
Output
You need $208333.34004181542 sales amount to make a commission of + 30000.0