学习记录——java 奖金-利润

题目

企业发放的奖金根据利润提成。利润(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);

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值