*5.39(金融应用:求销售总额)假设你正在某百货商店开始销售工作。你的工资包括基本工资和提成。基本工资是5000美元。使用下面的方案确定你的提成率。
销售额 | 提成率 |
---|---|
0.01~5000美元 | 8% |
5000.01~10000美元 | 10% |
10000.01美元及以上 | 12% |
你的目标是一年挣30000美元。编写程序找出为挣到30000美元,你所必须完成的最小销售额。
*5.39 (Financial application: find the sales amount) You have just started a sales job in a department store. Your pay consists of a base salary and a commission. The base salary is $5,000. The scheme shown below is used to determine the commission rate.
Sales Amount | Commission Rate |
---|---|
$0.01~$5000 | 8% |
$5000.01~$10000 | 10% |
$10000.01 and above | 12% |
Your goal is to earn $30,000 a year. Write a program to find the minimum sales you have to generate in order to make $30,000.
下面是参考答案代码:
public class FindTheSalesAmountQuestion39 {
public static void main(String[] args) {
final int BASE_SALARY = 5000;
int salesAmount = 10000;
double mySalary;
do {
mySalary = BASE_SALARY + 5000 * 0.08 + 5000 * 0.10 + (salesAmount-10000) * 0.12;
salesAmount++;
} while (mySalary < 30000);
System.out.printf("The minimum sales you have to generate is %d", salesAmount);
}
}
运行效果:
注:编写程序要养成良好习惯
1.文件名要用英文,具体一点
2.注释要英文
3.变量命名要具体,不要抽象(如:a,b,c等等),形式要驼峰化
4.整体书写风格要统一(不要这里是驼峰,那里是下划线,这里的逻辑段落空三行,那里相同的逻辑段落空5行等等)
5.普通变量,方法名要小驼峰,类名要大驼峰,常量要使用全部大写加上下划线命名法
6.要学习相应的代码编辑器的一些常用快捷键,如:快速对齐等等