File tree 1 file changed +24
-4
lines changed
src/com/github/jonathanbirkey/chapter05
1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change 2
2
* @author : Jonathan Birkey
3
3
4
4
* @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.
8
9
*/
9
10
package com .github .jonathanbirkey .chapter05 ;
10
11
12
+ import java .util .Scanner ;
13
+
11
14
public class Exercise42 {
12
15
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 );
14
34
}
15
35
}
You can’t perform that action at this time.
0 commit comments