Skip to content

Commit 01d3d3e

Browse files
finished exercise 39
1 parent 3e1db12 commit 01d3d3e

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/com/github/jonathanbirkey/chapter05/Exercise39.java

+29-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,38 @@
22
* @author : Jonathan Birkey
33
* @mailto : [email protected]
44
* @created : 28Feb2024
5-
* <p>(Display leap years) Write a program that displays all the leap years, 10 per line, from
6-
* 101 to 2100, separated by exactly one space. Also display the number of leap years in this
7-
* period.
5+
* <p>(Financial application: find the sales amount) You have just started a sales job in a
6+
* department store. Your pay consists of a base salary and a commission. The base salary is
7+
* $5,000. The scheme shown below is used to determine the commission rate.
8+
* <p>Sales Amount - Commission Rate
9+
* <p>$0.01–$5,000 - 8%
10+
* <p>$5,000.01–$10,000 - 10%
11+
* <p>$10,000.01 and above - 12%
12+
* <p>Note this is a graduated rate. The rate for the first $5,000 is at 8%, the next $5,000 is
13+
* at 10%, and the rest is at 12%. If the sales amount is 25,000, the commission is 5,000 * 8 +
14+
* 5,000 * 10 + 15,000 * 12 = 2,700
15+
* <p>Your goal is to earn $30,000 a year. Write a program that finds out the minimum number of
16+
* sales you have to generate in order to make $30,000.
817
*/
918
package com.github.jonathanbirkey.chapter05;
1019

1120
public class Exercise39 {
1221
public static void main(String[] args) {
13-
// TODO: solve
22+
double baseSalary = 5000;
23+
double commission = 0;
24+
double desiredEarnings = 30000;
25+
double sales = 0;
26+
27+
while (commission + baseSalary < desiredEarnings) {
28+
if (sales <= 5000) {
29+
commission = sales * 0.08;
30+
} else if (sales <= 10000) {
31+
commission = (5000 * 0.08) + ((sales - 5000) * 0.10);
32+
} else {
33+
commission = (5000 * 0.08) + (5000 * .10) + ((sales - 10000) * 0.12);
34+
}
35+
sales++;
36+
}
37+
System.out.printf("You would need to make $%.2f in sales to make at least $30,0000.", sales);
1438
}
15-
}
39+
}

0 commit comments

Comments
 (0)