一、已知提成计算销售额
package exercise;
import javax.swing.JOptionPane;
public class FinalSalesAmount {
public static void main(String[] args) {
final double COMMISSION_SOUGHT=25000; //常量前面要加final,常量必须全部大写,目标提成
final double INITIAL_SALES_AMOUNT=0.01;
double commission=0; //设定提成初始量为0
double salesAmount=INITIAL_SALES_AMOUNT; //设定初始销售额为0.01
do{
salesAmount+=0.01;
//每次循环时给销售额加上0.01,注意,销售额的递加只能放到前面,如果放到后面循环结束时销售额比要求的多出0.01美分
if(salesAmount>=10000.01)
commission=5000*0.08+5000*0.1+(salesAmount-10000)*0.12;
else if(salesAmount>=5000.01)
commission=5000*0.08+(salesAmount-5000)*0.10;
else
commission=salesAmount*0.08;
}while(commission<COMMISSION_SOUGHT); //当提成大于或等于目标提成量时停止循环
JOptionPane.showMessageDialog(null, "要达到"+COMMISSION_SOUGHT+"美元的提成 \n需要的销售额为:"+(int)(salesAmount*100)/100.0+"美元");
}
}