/*
2017年3月6日15:19:01
java基础50道经典练习题 例12
Athor: ZJY
Purpose:
【程序12】
题目:企业发放的奖金根据利润提成。利润(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,
求应发放奖金总数?
程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。
*/
import ;
public class ProgramNo12_1
{
public static void main(String[] args)
{
("请输入当前的利润: ");
Scanner sc = new Scanner();
long profit = ();
("应发奖金为: "+bonus(profit)+"元!");
}
private static long bonus(long profit)
{
long bonusValue = 0;
("输入的利润为: %d元\n",profit);
if(100000 >= profit) {
bonusValue = (long)(profit*0.1);
}else if((100000 < profit)&&(200000 >= profit)) {
bonusValue = (long)((profit-100000)*0.075 + 100000*0.1);
}else if((200000 < profit)&&(400000 >= profit)) {
bonusValue = (long)((profit-200000)*0.05 + (200000-100000)*0.075 + 100000*0.1);
}else if((400000 < profit)&&(600000 >= profit)) {
bonusValue = (long)((profit-400000)*0.03
+ (400000-200000)*0.05 + (200000-100000)*0.075 + 100000*0.1);
}else if((600000 < profit)&&(1000000 >= profit)) {
bonusValue = (long)((profit-600000)*0.015
+ (600000-400000)*0.03 + (400000-200000)*0.05 + (200000-100000)*0.075 + 100000*0.1);
}else if(1000000 < profit) {
bonusValue = (long)((profit-1000000)*0.01
+ (1000000-600000)*0.015 + (600000-400000)*0.03
+ (400000-200000)*0.05 + (200000-100000)*0.075 + 100000*0.1);
}
return bonusValue;
}
}
/*
2017年3月6日15:19:01
java基础50道经典练习题 例12
Athor: ZJY
Purpose:
*/
import .*;
public class ProgramNo12_2
{
public static void main(String[] args){
("请输入当前利润:");
long profit = (key_Input());
("应发奖金:"+bonus(profit));
}
//接受从键盘输入的内容
private static String key_Input(){
String str = null;
BufferedReader bufIn = new BufferedReader(new InputStreamReader());
try{
str = ();
}catch(IOException e){
();
}finally{
try{
();
}catch(IOException e){
();
}
}
return str;
}
//计算奖金
private static long bonus(long profit){
long prize = 0;
long profit_sub = profit;
if(profit_sub > 1000000){
profit = profit_sub-1000000;
profit_sub = 1000000;
prize += profit*0.01;
}
if(profit_sub > 600000){
profit = profit_sub-600000;
profit_sub = 600000;
prize += profit*0.015;
}
if(profit_sub > 400000){
profit = profit_sub-400000;
profit_sub = 400000;
prize += profit*0.03;
}
if(profit_sub > 200000) {
profit = profit_sub-200000;
profit_sub = 200000;
prize += profit*0.05;
}
if(profit_sub > 100000){
profit = profit_sub-100000;
profit_sub = 100000;
prize += profit*0.075;
}
prize += profit_sub*0.1;
//("5此时的奖金为: %d, %d元\n",profit_sub, prize);
return prize;
}
}