題目:企業發放的獎金根據利潤提成。
利潤(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,求應發放獎金總數?
程序分析:請利用數軸來分界,定位。注意定義時需把獎金定義成長整型。
public class 第十二題根據提成發放獎金 { public static void main(String[] args) { System.out.print("請輸入利潤金額:"); Scanner in = new Scanner(System.in); double bonus = 0; //獎金
double profit = in.nextDouble(); //利潤
in.close(); if(profit<=0) { System.out.println("輸入錯誤"); } else if(profit > 0 && profit <= 10) { //小於10萬
bonus = profit * 0.1; } else if(profit > 10 && profit <20) { //10-20萬
bonus = (profit-10) * 0.075 + 1; } else if(profit >=20 && profit <40) { //20-40萬
bonus = (profit-20)*0.05 + 1.75; } else if(profit >=40 && profit < 60) { //40-60萬
bonus = (profit-40)*0.03 + 2.75; } else if(profit >=60 && profit < 100) { //60-100萬
bonus = (profit-60)*0.015 + 3.35; } else { bonus = (profit-100)*0.001 + 3.95; //大於100萬
} System.out.println("獎金為:"+ (bonus*10000) +"元"); } }