以下是一个计算奖金的 Java 代码示例:

public class BonusCalculator {
    public static void main(String[] args) {
        double profit = 100000; // 利润
        double bonus; // 奖金

        if (profit <= 100000) {
            bonus = profit * 0.1;
        } else if (profit <= 200000) {
            bonus = 100000 * 0.1 + (profit - 100000) * 0.075;
        } else if (profit <= 400000) {
            bonus = 100000 * 0.1 + 100000 * 0.075 + (profit - 200000) * 0.05;
        } else if (profit <= 600000) {
            bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (profit - 400000) * 0.03;
        } else if (profit <= 1000000) {
            bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (profit - 600000) * 0.015;
        } else {
            bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (profit - 1000000) * 0.01;
        }

        System.out.println('奖金金额为:' + bonus);
    }
}

这段代码根据利润的不同范围计算奖金金额。根据题目的要求,利润在不同范围内有不同的提成比例。代码中使用了 if-else if-else 结构来判断利润所在的范围,并根据不同的范围计算奖金金额。最后,将计算得到的奖金金额输出到控制台。

Java 代码示例:根据利润计算奖金

原文地址: https://www.cveoy.top/t/topic/ouIq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录