关于利润提成问题!
企业发放的奖金根据利润提成。利润(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 java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; public class Profit extends JFrame{ private Container container; private JPanel inputPanel; private JLabel label; private JTextArea area; private JTextField field; private JButton button; public Profit(){ super("提成计算"); container = getContentPane(); inputPanel = new JPanel(new FlowLayout()); label = new JLabel("请输入利润(万元)"); field = new JTextField(15); field.addActionListener(new Handler()); area = new JTextArea(5,20); area.setEditable(false); button = new JButton("计算提成"); button.addActionListener(new Handler()); inputPanel.add(label); inputPanel.add(field); inputPanel.add(button); container.add(inputPanel,BorderLayout.NORTH); container.add(area,BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); Dimension frameSize = getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((screenSize.width - frameSize.width)/2,(screenSize.height - frameSize.height)/2); setResizable(false); setVisible(true); } public static void main(String[] args) { new Profit(); } private class Handler implements ActionListener{ private double brokerage; //提成 public void actionPerformed(ActionEvent event){ brokerage = 0; area.setText(""); String text = field.getText().trim(); double value = 0d; try{ value = Double.parseDouble(text); if(value<0){ JOptionPane.showMessageDialog(container, "您输入的利润值为负,不能计算", "提示信息", JOptionPane.INFORMATION_MESSAGE); }else{ int level = (int)value/10; switch(level){ case 0: //0-10万元 brokerage += value/10; break; case 1: //10-20万元 brokerage += 10*0.1 + (value-10)*0.075; break; case 2: case 3: //20-40万元 brokerage += 10*0.1 + 10*0.075 + (value - 20) * 0.05; break; case 4: case 5: //40-60万元 brokerage += 10*0.1 + 10*0.075 + 20*0.05 + (value-40) * 0.03; break; case 6: case 7: case 8: case 9: //60-100万元 brokerage += 10*0.1 + 10*0.075 + 20*0.05 + 20 * 0.03 + (value-60)*0.015; break; default: //100万以上 brokerage += 10*0.1 + 10*0.075 + 20*0.05 + 20 * 0.03 + 40 * 0.03 + (value-60)*0.015 + (value-100) * 0.01; } } area.append("您的提成为:\n" + brokerage + "万元"); field.grabFocus(); }catch(NumberFormatException e){ JOptionPane.showMessageDialog(container, "请输入正确的数值", "提示信息", JOptionPane.INFORMATION_MESSAGE); field.setText(""); field.grabFocus(); } } } }
[[it] 本帖最后由 freish 于 2008-9-19 00:34 编辑 [/it]]