工资结算小程序--VE_VE

这是上软件测试课程写的一个简单的工资发放小程序,就是输入工资,然后根据薪制和错误程度计算出实发工资

规则就是年薪制+PT:0.02,年薪制+YZ:0.04

月薪制+PT:0.04,月薪制+YZ:0.08的扣款比例

emmm....就这么点东西的课堂作业

public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setContentPane(new GiveMoneyPanel(frame));
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public MainFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 580);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}

}
public class GiveMoneyPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JTextField tfdSalary;
private JTextField tfdName;
private JTextField tfdNum;
private JTextField tfdScale;
private JTextField tfdCut;
private JTextField tfdFact;
private final ButtonGroup btnGro1 = new ButtonGroup();
private final ButtonGroup btnGro2 = new ButtonGroup();

private JRadioButton rdbNX = null;
private JRadioButton rdbYN = null;
private JRadioButton rdbYZ = null;
private JRadioButton rdbPT = null;
private JRadioButton rdbNot = null;

/**
* Create the panel.
*/
@SuppressWarnings("unused")
private JFrame mainFrame = null;
public GiveMoneyPanel(JFrame mainFrame) {
setLayout(null);

this.mainFrame = mainFrame;

JButton btnCancel = new JButton("取消");
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//取消按钮,将所有信息清除
tfdSalary.setText("");
tfdName.setText("");
tfdNum.setText("");
tfdScale.setText("");
tfdCut.setText("");
tfdFact.setText("");
}
});
btnCancel.setForeground(new Color(128, 128, 0));
btnCancel.setFont(new Font("宋体", Font.PLAIN, 14));
btnCancel.setBounds(240, 486, 103, 39);
add(btnCancel);

JButton btnYes = new JButton("确定");
btnYes.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//确定按钮--结算
//1.组织数据
String salary = tfdSalary.getText();
double sala = StringToDoubel.toDoubel(salary);
if(sala==-1){
return ;
}
int gro1 = rdbNX.isSelected()?1:2;
int gro2 = 0;
gro2 = rdbPT.isSelected()?1:gro2;
gro2 = rdbYZ.isSelected()?2:gro2;
//2.调用逻辑层
Man man = new Man();
man.setNum(tfdNum.getText());
man.setName(tfdName.getText());
man.setSalary(sala);
man.setInstitution(gro1);
man.setWrong(gro2);
man = new BusinessCount().count(man);
//3.显示数据
tfdScale.setText(""+man.getScale());
tfdCut.setText(""+man.getDeMoney());
tfdFact.setText(""+man.getFactSalary());
}
});
btnYes.setForeground(new Color(128, 128, 0));
btnYes.setFont(new Font("宋体", Font.PLAIN, 14));
btnYes.setBounds(106, 485, 103, 39);
add(btnYes);

JLabel label = new JLabel("本月工资:");
label.setForeground(new Color(85, 107, 47));
label.setFont(new Font("微软雅黑", Font.BOLD, 15));
label.setBounds(116, 158, 80, 22);
add(label);

tfdSalary = new JTextField();
tfdSalary.setColumns(10);
tfdSalary.setBounds(209, 160, 127, 23);
add(tfdSalary);

tfdName = new JTextField();
tfdName.setColumns(10);
tfdName.setBounds(209, 118, 127, 23);
add(tfdName);

JLabel label_1 = new JLabel("姓 名:");
label_1.setForeground(new Color(85, 107, 47));
label_1.setFont(new Font("微软雅黑", Font.BOLD, 15));
label_1.setBounds(116, 116, 80, 22);
add(label_1);

JLabel label_2 = new JLabel("员工编号:");
label_2.setForeground(new Color(85, 107, 47));
label_2.setFont(new Font("微软雅黑", Font.BOLD, 15));
label_2.setBounds(116, 74, 80, 22);
add(label_2);

tfdNum = new JTextField();
tfdNum.setColumns(10);
tfdNum.setBounds(209, 74, 127, 23);
add(tfdNum);

JLabel label_3 = new JLabel("工资发放系统");
label_3.setForeground(Color.RED);
label_3.setFont(new Font("微软雅黑", Font.BOLD, 16));
label_3.setBounds(178, 10, 103, 22);
add(label_3);

JLabel label_4 = new JLabel("基本信息");
label_4.setForeground(new Color(85, 107, 47));
label_4.setFont(new Font("微软雅黑", Font.BOLD, 15));
label_4.setBounds(115, 43, 80, 22);
add(label_4);

JLabel label_5 = new JLabel("扣款比例:");
label_5.setForeground(new Color(85, 107, 47));
label_5.setFont(new Font("微软雅黑", Font.BOLD, 15));
label_5.setBounds(116, 340, 80, 22);
add(label_5);

tfdScale = new JTextField();
tfdScale.setEditable(false);
tfdScale.setColumns(10);
tfdScale.setBounds(209, 340, 127, 23);
add(tfdScale);

tfdCut = new JTextField();
tfdCut.setEditable(false);
tfdCut.setColumns(10);
tfdCut.setBounds(209, 384, 127, 23);
add(tfdCut);

JLabel label_6 = new JLabel("扣款金额:");
label_6.setForeground(new Color(85, 107, 47));
label_6.setFont(new Font("微软雅黑", Font.BOLD, 15));
label_6.setBounds(116, 382, 80, 22);
add(label_6);

JLabel label_7 = new JLabel("实发工资:");
label_7.setForeground(new Color(85, 107, 47));
label_7.setFont(new Font("微软雅黑", Font.BOLD, 15));
label_7.setBounds(116, 424, 80, 22);
add(label_7);

tfdFact = new JTextField();
tfdFact.setEditable(false);
tfdFact.setColumns(10);
tfdFact.setBounds(209, 426, 127, 23);
add(tfdFact);

rdbNX = new JRadioButton("年薪制NX");
rdbNX.setSelected(true);
btnGro1.add(rdbNX);
rdbNX.setFont(new Font("宋体", Font.PLAIN, 12));
rdbNX.setBounds(207, 232, 78, 23);
add(rdbNX);

rdbYN = new JRadioButton("月薪制YN");
rdbYN.setFont(new Font("宋体", Font.PLAIN, 12));
btnGro1.add(rdbYN);
rdbYN.setBounds(282, 233, 121, 23);
add(rdbYN);

rdbYZ = new JRadioButton("严重YZ");
rdbYZ.setFont(new Font("宋体", Font.PLAIN, 12));
btnGro2.add(rdbYZ);
rdbYZ.setBounds(322, 265, 71, 23);
add(rdbYZ);

rdbPT = new JRadioButton("普通PT");
rdbPT.setFont(new Font("宋体", Font.PLAIN, 12));
btnGro2.add(rdbPT);
rdbPT.setBounds(257, 265, 78, 23);
add(rdbPT);

JLabel label_8 = new JLabel("工资薪制:");
label_8.setForeground(new Color(85, 107, 47));
label_8.setFont(new Font("微软雅黑", Font.BOLD, 15));
label_8.setBounds(115, 231, 80, 22);
add(label_8);

JLabel label_9 = new JLabel("错误程度:");
label_9.setForeground(new Color(85, 107, 47));
label_9.setFont(new Font("微软雅黑", Font.BOLD, 15));
label_9.setBounds(114, 264, 80, 22);
add(label_9);

rdbNot = new JRadioButton("无");
rdbNot.setSelected(true);
btnGro2.add(rdbNot);
rdbNot.setFont(new Font("宋体", Font.PLAIN, 12));
rdbNot.setBounds(209, 265, 62, 23);
add(rdbNot);

}
}
public class BusinessCount {
public Man count(Man man){
//1.扣款比例
double scale = 0;
if(man.getWrong()!=0){//进这里就是有错,需要扣工资了
scale = man.getInstitution()==Man.NX ? 0.02 : 0.04;//薪制
scale = man.getWrong()==Man.PT ? scale : scale*2;//错误程度
}
man.setScale(scale);

//2.扣款金额
double deMoney = man.getSalary()*scale;
man.setDeMoney(deMoney);

//3.实际工资
double factSalary = man.getSalary()-deMoney;
man.setFactSalary(factSalary);

return man;
}
}
public class Man {
String num;
String name;
double salary;//本月工资
int institution;//1,2必选一个,1表示年薪制,2表示月薪制
int wrong;//0,1,2可以不选,0表示没错误,1表示普通错误,2表示严重错误
double scale;//扣款比例
double deMoney;//扣款
double factSalary;//实发工资

public Man() {
super();
}

public static final int NX = 1;
public static final int YN = 2;
public static final int WU = 0;
public static final int PT = 1;
public static final int YZ = 2;
public Man(String num, String name, double salary, int institution, int wrong, double scale, double deMoney,
double factSalary) {
super();
this.num = num;
this.name = name;
this.salary = salary;
this.institution = institution;
this.wrong = wrong;
this.scale = scale;
this.deMoney = deMoney;
this.factSalary = factSalary;
}

public String getNum() {
return num;
}

public void setNum(String num) {
this.num = num;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public int getInstitution() {
return institution;
}

public void setInstitution(int institution) {
this.institution = institution;
}

public int getWrong() {
return wrong;
}

public void setWrong(int wrong) {
this.wrong = wrong;
}

public double getScale() {
return scale;
}

public void setScale(double scale) {
this.scale = scale;
}

public double getDeMoney() {
return deMoney;
}

public void setDeMoney(double deMoney) {
this.deMoney = deMoney;
}

public double getFactSalary() {
return factSalary;
}

public void setFactSalary(double factSalary) {
this.factSalary = factSalary;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Man other = (Man) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}

@Override
public String toString() {
return "Man [salary=" + salary + ", institution=" + institution + ", wrong=" + wrong + ", scale=" + scale
+ ", deMoney=" + deMoney + ", factSalary=" + factSalary + "]";
}
}


        

public class StringToDoubel {
public static double toDoubel(String string){
double res = 0;
try {
res = Double.parseDouble(string);
} catch (NumberFormatException e) {
res = -1;
JOptionPane.showMessageDialog(null, "请输入正确金额");
}
return res;
}
}