# 结对作业2

### 3.代码原理分析:###

1.算式个数选项

JLabel num = new JLabel("\u7B97\u5F0F\u4E2A\u6570");
num.setBounds(10, 10, 60, 15);


2.最大数选项

JLabel max = new JLabel("\u6700\u5927\u6570");
max.setBounds(10, 45, 65, 15);


3.运算符选项

 JLabel operate = new JLabel("\u8FD0\u7B97\u7B26");
operate.setBounds(10, 76, 40, 23);

JCheckBox Sub = new JCheckBox("-");
Sub.setBounds(110, 76, 50, 23);

JCheckBox Mult = new JCheckBox("*");
Mult.setBounds(56, 114, 50, 23);

JCheckBox Div = new JCheckBox("/");
Div.setBounds(110, 114, 50, 23);


4.先序遍历

public List<Integer> preorderTraversal(TreeNode root) {
if(root == null)
return res;
Stack<TreeNode> stack = new Stack<>();
stack.push(root);
while(!stack.isEmpty()){
TreeNode node = stack.pop();
if(node.right != null){
stack.push(node.right);
}
if(node.left != null){
stack.push(node.left);
}
}
return res;
}


4.括号选项

    JLabel bracketer = new JLabel("\u62EC \u53F7");
bracketer.setBounds(10, 149, 35, 23);

khY.setBounds(56, 149, 35, 23);

khN.setBounds(110, 149, 40, 23);

ButtonGroup groupkuohao = new ButtonGroup();


5.小数点选项

JLabel point = new JLabel("\u5C0F \u6570");
point.setBounds(10, 182, 35, 23);

xsY.setBounds(56, 182, 35, 23);

xsN.setBounds(110, 182, 40, 23);

ButtonGroup groupxiaoshu = new ButtonGroup();


6.输出方式选项

 JLabel outMethod = new JLabel("\u8F93\u51FA\r\n\u65B9\u5F0F");
outMethod.setBounds(10, 220, 54, 15);

outMethodF.setBounds(70, 216, 60, 23);

outMethodP.setBounds(130, 216, 70, 23);

ButtonGroup prin = new ButtonGroup();


7.输出按钮及按钮的Lisetener实现

JButton button = new JButton("\u751F\u6210\u7B97\u5F0F");
public void actionPerformed(ActionEvent arg0) {
String n1 = numtxt.getText();
int num = Integer.parseInt(n1);
String n2 = maxtxt.getText();
int max = Integer.parseInt(n2);
int[] a = {0,0,0,0};
int kh=0,outp=0,xs=0;
a[0] = 1;
if(Sub.isSelected())
a[1] = 1;
if(Mult.isSelected())
a[2] = 1;
if(Div.isSelected())
a[3] = 1;
if(khY.isSelected()) {
kh = 1;
}else {
kh = 0;
}
if(xsY.isSelected()) {
xs = 1;
}else {
xs = 0;
}
if(outMethodF.isSelected()) {
outp = 1;
}else {
outp = 0;
}
view.out(num,max,a,kh,xs,outp);
}
});


### 5.代码整体评价:###

• 代码较为规范,有必要的注释
• 变量命名遵循java的推荐规范,使用了驼峰命名法
• 单个函数执行单一的功能,代码行数少
• 缺少对异常的捕获和处理

### 代码优点:

• 尽量使用了java.util包的类,避免了自己写实现代码时出现错误的可能性,如使用了 java.util包的Queue类,ArrayList类,Stack类,使得程序健壮性有所提高.
• 代码风格清晰明了,{}使用得当,表达式里使用了使可读性提高的空格,多个变量分开多行声明,且变量名很规范,清晰易懂.
• 代码的每个子函数功能都有注释,且函数的代码功能实现了单一的功能,代码行数少,可读性和可维护性较高.

### 代码缺点###

• 没有异常处理部分,出现异常参数,会使程序奔溃.

### 6.总结###

posted @ 2019-05-06 22:24  Daft-Punk  阅读(149)  评论(0编辑  收藏  举报