第五章第四十二题(金融应用:求销售额)(Financial application: find the sales amount)

第五章第四十二题(金融应用:求销售额)(Financial application: find the sales amount)

  • *5.42(金融应用:求销售额)如下重写编程练习题5.39:
    使用for循环替代do-while循环。
    允许用户自己输入COMMISSION_SOUGHT而不是将它固定为一个常量。
    *5.42 (Financial application: find the sales amount) Rewrite Programming Exercise 5.39 as follows:
    Use a for loop instead of a do-while loop.
    Let the user enter COMMISSION_SOUGHT instead of fixing it as a constant.
  • 参考代码:
package chapter05;

import java.util.Scanner;

public class Code_42 {
    public static void main(String[] args) {
        final double COMMISSION_SOUGHT;
        int salesAmount = 10000;
        double mySalary = 0;
        System.out.print("Enter your base salary: ");
        Scanner inputScanner = new Scanner(System.in);
        COMMISSION_SOUGHT = inputScanner.nextDouble();
        for(;mySalary < 30000;salesAmount++)
            mySalary = COMMISSION_SOUGHT + 5000 * 0.08 + 5000 * 0.10 + (salesAmount-10000) * 0.12;
        System.out.printf("The minimum sales you have to generate is %d", salesAmount);
    }
}

  • 结果显示:
Enter your base salary: 5000
The minimum sales you have to generate is 210835
Process finished with exit code 0

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值