Skip to content

Commit 54643ac

Browse files
finished exercise 42
1 parent 12b996b commit 54643ac

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

+24-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,34 @@
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) Rewrite Programming Exercise 5.39 as
6+
* follows:
7+
* <p>Use a for loop instead of a do-while loop.
8+
* <p>Let the user enter COMMISSION_SOUGHT instead of fixing it as a constant.
89
*/
910
package com.github.jonathanbirkey.chapter05;
1011

12+
import java.util.Scanner;
13+
1114
public class Exercise42 {
1215
public static void main(String[] args) {
13-
// TODO: solve
16+
Scanner input = new Scanner(System.in);
17+
System.out.print("Enter commission sought: ");
18+
double desiredCommission = input.nextDouble();
19+
double commission = 0;
20+
double sales = 0;
21+
22+
for (int i = 0; commission < desiredCommission; i++) {
23+
if (sales <= 5000) {
24+
commission = sales * 0.08;
25+
} else if (sales <= 10000) {
26+
commission = (5000 * 0.08) + ((sales - 5000) * 0.10);
27+
} else {
28+
commission = (5000 * 0.08) + (5000 * .10) + ((sales - 10000) * 0.12);
29+
}
30+
sales = i;
31+
}
32+
33+
System.out.printf("You would need to make $%.2f in sales to make at least $%.2f in commision.", sales, desiredCommission);
1434
}
1535
}

0 commit comments

Comments
 (0)