题目
企业发放的奖金根据利润提成。利润(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),求应发放奖金总数?
0--10%-->10万--7.5%-->20万--5%-->40万--3%-->60万--1.5%-->100万--1%-->infinity
以下
import java.util.Scanner;
public class Bonus {
public static void main(String[] args) {
long bonus=0;
Scanner sc= new Scanner(System.in); // 从键盘接收利润值
System.out.println("输入利润");
long profit =sc.nextLong();
sc.close();
if(profit<=100000){
bonus = Math.round(profit*0.1); // 由于bonus是long型,而profit*0.1为double型
//故用Math.round()方法进行转换
}else if(profit<200000){
bonus = Math.round((profit-100000)*0.075+10000); //超出十万部分乘以0.075,十万以内乘以0.1
}else if(profit<400000){
bonus = Math.round((profit-200000)*0.05+10000+7500);
}else if(profit<600000){
bonus = Math.round((profit-400000)*0.03+10000+7500+10000);
}else if(profit<1000000){
bonus = Math.round((profit-600000)*0.015+10000+7500+10000+6000);
}else{
bonus = Math.round((profit-1000000)*0.01+10000+7500+10000+6000+6000);
}
System.out.println("奖金为"+bonus);
}
}