12 【程序 12 计算奖金】

题目:企业发放的奖金根据利润提成。利润(I)低于或等于 10 万元时,奖金可提 10%;利润高于 10 万元, 低于 20 万元时,低于 10 万元的部分按 10%提成,高于 10 万元的部分,可可提成 7.5%;20 万到 40 万之间 时,高于 20 万元的部分,可提成 5%;40 万到 60 万之间时高于 40 万元的部分,可提成 3%;60 万到 100 万 之间时,高于 60 万元的部分,可提成 1.5%,高于 100 万元时,超过 100 万元的部分按 1%提成,从键盘输 入当月利润 I,求应发放奖金总数?

程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。

package cskaoyan;

public class cskaoyan12 {
@org.junit.Test
public void count() {
java.util.Scanner in = new java.util.Scanner(System.in);
double profit = in.nextDouble();
double bonus = 0;
double percent1 = 0.1;
double percent2 = 0.075;
double percent3 = 0.05;
double percent4 = 0.03;
double percent5 = 0.015;
double percent6 = 0.01; if (profit <= 100000) {
bonus = profit * percent1;
} else if (profit <= 200000) {
bonus = 100000 * percent1 + (profit - 100000) * percent2;
} else if (profit <= 400000) {
bonus = 100000 * percent1 + (200000 - 100000) * percent2 + (profit - 200000) * percent3;
} else if (profit <= 600000) {
bonus = 100000 * percent1 + (200000 - 100000) * percent2 + (400000 - 200000) * percent3
+ (profit - 400000) * percent4;
} else if (profit <= 1000000) {
bonus = 100000 * percent1 + (200000 - 100000) * percent2 + (400000 - 200000) * percent3
+ (600000 - 400000) * percent4 + (profit - 600000) * percent5;
} else {
bonus = 100000 * percent1 + (200000 - 100000) * percent2 + (400000 - 200000) * percent3
+ (600000 - 400000) * percent4 + (1000000 - 600000) * percent5 + (profit - 1000000) * percent6;
} System.out.println(bonus);
in.close();
}
}
05-11 19:59