java一般项目提成多少_java面试之经典提成问题

〈计算提成〉

10万(含)以下 10%提成

10-20万(含)部分7.5%提成

20-40万(含)部分5%

40-60万(含)部分3.5%

60-100万(含)部分1.5%

100万以上1%

public class CounterPercentage {

public static final double level1 = 0.1;

public static final double level2 = 0.075;

public static final double level3 = 0.05;

public static final double level4 = 0.03;

public static final double level5 = 0.015;

public static final double level6 = 0.01;

public static final double bound1 = 100000; //0-100000

public static final double bound2 = 200000; //100000-200000

public static final double bound3 = 400000; //200000-400000

public static final double bound4 = 600000; //400000-600000

public static final double bound5 = 1000000; //600000-100000

public static void main(String[] args) {

System.out.println("请输入净利润:");

Scanner scanner = new Scanner(System.in);

if(scanner.hasNextDouble()){

System.out.println("提成为:"+getPercentage(scanner.nextDouble()));

}

else {

System.out.println("请输入的净利润不合法,请确定后再输入!");

}

}

/**

* 根据输入的净利润计算出提成

* @param netProfits 净利润

* @return 提成

*/

private static double getPercentage(double netProfits ) {

double percentage = 0.0;

if(netProfits <= bound1){

percentage += netProfits*level1;

}

else if(netProfits <= bound2 ){

percentage += getPercentage(bound1) + (netProfits - bound1)*level2;

}

else if(netProfits <= bound3){

percentage += getPercentage(bound2) + ( netProfits - bound2)*level3;

}

else if(netProfits <= bound4){

percentage += getPercentage(bound3) + (netProfits - bound3)*level4;

}

else if(netProfits <= bound5){

percentage += getPercentage(bound4) + (netProfits - bound4)*level5;

}

else if(netProfits > bound5){

percentage += getPercentage(bound5) + (netProfits - bound5)*level6;

}

return percentage;

}

}

测试结果:

1159007914ba

image.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值