结对编程1-四则运算题目生成器改进

结对编程1-四则运算题目生成器改进(201421123047,201421123029(网络1411班))

题目要求:

    1. 我们在个人作业1中,用各种语言实现了一个命令行的四则运算小程序。进一步,本次要求把这个程序做成GUI(可以是Windows PC 上的,也可以是Mac、Linux,web,手机上的),成为一个有基本功能、一定价值的程序。在下面的功能需求中实现两个:

      1. 记录用户的对错总数,程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算。
      2. 有计时功能,能显示用户开始答题后的消耗时间。
      3. 界面支持中文简体/中文繁体/英语,用户可以选择一种;

需求分析:

  1. 计时功能:答题时知道自己花费时间,更了解自己答题效率.
  2. 语言选择:满足不同用户的需求,实现语言的自由切换.

程序设计:

       主要功能流程图:

                               

 

 

 代码展示:

                            计时功能:

 

 public void actionPerformed(ActionEvent e) {//计时功能
              tishu=Integer.parseInt(T1.getText());
              noanswer=tishu-dadui-dacuo;
              summary++;
              timer = new Timer(); 
              finishtime=System.currentTimeMillis();
              starttime=finishtime;
              timer.schedule(new TimerTask() 
              {
                  public void run() {    
                      finishtime=System.currentTimeMillis();
                      duration=finishtime-starttime;
                      if(duration/1000==25&&summary<tishu)
                      {
                          JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",为答题题数"+(tishu-dacuo-dadui)+",答题使用时间:"+(allduration+duration)/1000+"秒。");
                          frame.setVisible(false);
                          new Jm();
                      }
                      String str=df.format(new Date(duration)); 
                      T7.setText(str);
                      }  
                  }, 1000, 1000);

 

                                     

 

 

                           语言选择:

public class Yyxz {
    private JFrame frame;
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
    public void run() {
                try {
                    Yyxz window = new Yyxz();
                    window.frame.setVisible(true);
                } 
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    public Yyxz() {
        initialize();
    }
    private void initialize() {
        //设置界面的布局
        frame = new JFrame();
        frame.setTitle("语言选择");
        frame.setBounds(100, 100, 325, 397);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        JButton btnNewButton = new JButton("简体中文");
        btnNewButton.setFont(new Font("宋体", Font.PLAIN, 22));
        
        JButton button = new JButton("繁体中文");
        button.setFont(new Font("宋体", Font.PLAIN, 22));
        
        JButton button_1 = new JButton("英文");
        button_1.setFont(new Font("宋体", Font.PLAIN, 22));
        
        JButton btnNewButton_1 = new JButton("退出");
        btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 18));
        GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
        groupLayout.setHorizontalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
        .addGroup(groupLayout.createSequentialGroup()
                    .addContainerGap(57, Short.MAX_VALUE)
                    .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
                    .addGroup(groupLayout.createSequentialGroup()
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(btnNewButton, GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
                    .addComponent(button, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(button_1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGap(68))
                    .addGroup(groupLayout.createSequentialGroup()
                    .addGap(118)
                    .addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(119, Short.MAX_VALUE))
        );
        groupLayout.setVerticalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
        .addGroup(groupLayout.createSequentialGroup()
                    .addGap(42)
                    .addComponent(btnNewButton)
                    .addGap(57)
                    .addComponent(button, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
                    .addGap(57)
                    .addComponent(button_1, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
                    .addComponent(btnNewButton_1)
                    .addGap(26))
        );
        
        btnNewButton_1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                frame.setVisible(false);
                new Jm();}
        });
        
        btnNewButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                frame.setVisible(false);
                new Jm();
            }            
        });
        
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                frame.setVisible(false);
                new Jm();
            }            
        });
       
        button_1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                frame.setVisible(false);
                new Jm2();
            }            
        });
        frame.getContentPane().setLayout(groupLayout);
        //设置窗口的位置
        Toolkit kit = Toolkit.getDefaultToolkit();        
        Dimension screenSize = kit.getScreenSize();        
        int w1 = screenSize.width;        
        int h = screenSize.height;        
        int x1 = w1/3;        
        int y1 = h/5;    
        frame.setLocation(x1,y1);
        frame.setVisible(true);//设置窗口的可见性
        frame.setResizable(false);//设置窗口大小的不可变性
    }

}

功能截图:

 

 

PSP:

 

PSP2.1

Personal Software Process Stages

Time(min) Senior Student

Time (min)

Planning

计划

20

25

Estimate

估计这个任务需要多少时间

20

25

Development

开发

300

350

Analysis

需求分析 (包括学习新技术)

20

20

Design Spec

生成设计文档

10

14

Design Review

设计复审

20

25

Coding Standard

代码规范

15

30

Design

具体设计

100

130

Coding

具体编码

350

400

Code Review

代码复审

30

30

Test

测试(自我测试,修改代码,提交修改)

30

16

Reporting

报告

10

10

 

测试报告

2

3

 

计算工作量

3

5

 

并提出过程改进计划

5

4

 

 

总结:

    首先,在这次编程中使我更加了解如何运用Java进行GUI界面的设计.其次,我也明白了代码的规范书写的重要性,特别是在结对编程中,如果按自己的想法随便定义,那么就可能导致队友不明白你写的代码,这也导致了编程无法进行下去,所以规范代码是非常有必要的.再次,我明白在编程中遇到问题时要学会自己查资料去解决,这样才会有更深的印象.总之,在这次编程中感觉自己还是有很多收获,编程能力得到了提高但还是需要加强.

https://git.coding.net/lqwe/rjgc.git

https://coding.net/u/weh/p/we/git/tree/master/

posted @ 2017-03-14 21:39  lqwe  阅读(219)  评论(2编辑  收藏  举报