201571030111/201571030131小学生四则运算符结对编程


A:需求分析:

(1)用实验二的方法随机生成20道加减乘除混合算式,用户用户输入算式答案,程序检查答案是否正确,每道题正确计5分,错误不计分,20道题测试结束后给出测试总分。

(2)程序为用户提供三种进阶四则运算练习功能选择:百以内整数算式(必做)、带括号算式、真分数算式练习。

(3)程序允许用户进行多轮测试,提供用户多轮测试分数柱状图。

(4)程序记录用户的答题结果,并可以进行多次测试。

(5)测试有计时功能,测试时动态显示用户开始答题后的消耗时间。

(6)程序人机交互界面是GUI界面(WEB页面、APP页面都可),界面支持中文简体(必做)/中文繁体/英语,用户可以进行语种选择。

B:软件设计:使用类图

C:核心功能代码展示:展示核心功能代码

(1)实现语言界面切换功能:设置三个按钮,分别为“简体中文”、“繁体中文”和“英文”,将窗体上所有的文字设置为一个变量,当任意一个按钮按下时,切换成该按钮对应的语言。

if(input.equals("S5"))//简体中文
            {
                La1="得分";
                La2="计时";
                La4="下一轮";
                La5="提交答案";
                La6="测评";
                La7="简体中文";
                La8="繁体中文";
                La9="英文";
                La10="整数运算";
                La11="分数运算";                
                l1.setText(La1);
                BT4.setText(La6);
                BT2.setText(La5);
                BT5.setText(La7);
                BT6.setText(La8);
                BT7.setText(La9);
                BT8.setText(La2);
                BT9.setText(La10);
                BT10.setText(La11);
            }    
            if(input.equals("S6"))//繁体中文
            {
                La1="得分";
                La2="計時";
                La4="下一輪";
                La5="提交答案";
                La6="測評";
                La7="簡體中文";
                La8="繁體中文";
                La9="英文";
                La10="整數運算";
                La11="分數運算";                
                l1.setText(La1);
                BT4.setText(La6);
                BT2.setText(La5);
                BT5.setText(La7);
                BT6.setText(La8);
                BT7.setText(La9);
                BT8.setText(La2);
                BT9.setText(La10);
                BT10.setText(La11);
                
            }    
            if(input.equals("S7"))
            {
                La1="Grade";
                La2="Time";
                La4="Next Turn";
                La5="Submit";
                La6="Measurement";
                La7="Simplified Chinese";
                La8="Traditional Chinese";
                La9="English";
                La10="Integer arithmetic";
                La11="Fraction arithmetic";        
                l1.setText(La1);
                BT4.setText(La6);
                BT2.setText(La5);
                BT5.setText(La7);
                BT6.setText(La8);
                BT7.setText(La9);
                BT8.setText(La2);
                BT9.setText(La10);
                BT10.setText(La11);    
            }

(2)得分统计功能:对“提交答案”按钮进行监听,获取所有输入的答案,于文本文档result1中的答案进行比较,每对一题得五分,在得分后的文本框中显示得分。

if(input.equals("S2"))//提交答案
            {
                String []res = new String[20];
                //获取结果数组
                try {
                    
                    int i = 1;
                    BufferedReader br = new BufferedReader(new FileReader("result1.txt"));
                    String nString = br.readLine();
                    res[0] = nString;
                    while (nString != null) {
                        nString=br.readLine();
                        res[i]= nString;
                        i++;
                        
                    }
                    br.close();
                } catch (Exception e) {
                }      
                int sum = 0;
                //获取答案内容
                if(a1.getText().equals(res[0]))
                {
                    sum += 5;    
                }
                if(a2.getText().equals(res[1]))
                    sum += 5;
                if(a3.getText().equals(res[2]))
                    sum += 5;
                if(a4.getText().equals(res[3]))
                    sum += 5;
                if(a5.getText().equals(res[4]))
                    sum += 5;
                if(a6.getText().equals(res[5]))
                    sum += 5;
                if(a7.getText().equals(res[6]))
                    sum += 5;
                if(a8.getText().equals(res[7]))
                    sum += 5;
                if(a9.getText().equals(res[8]))
                    sum += 5;
                if(a10.getText().equals(res[9]))
                    sum += 5;
                if(a11.getText().equals(res[10]))
                    sum += 5;
                if(a12.getText().equals(res[11]))
                    sum += 5;
                if(a13.getText().equals(res[12]))
                    sum += 5;
                if(a14.getText().equals(res[13]))
                    sum += 5;
                if(a15.getText().equals(res[14]))
                    sum += 5;
                if(a16.getText().equals(res[15]))
                    sum += 5;
                if(a17.getText().equals(res[16]))
                    sum += 5;
                if(a18.getText().equals(res[17]))
                    sum += 5;
                if(a19.getText().equals(res[18]))
                    sum += 5;
                if(a20.getText().equals(res[19]))
                    sum += 5;
                String sco = sum + "";
                l2.setText(sco);
                
                Grade.add(sco);
                        
            }

(3)计时功能:

       public void run() {    
            while (true) {    
                if (!stopped) {    
                    long elapsed = System.currentTimeMillis() - programStart - pauseCount;    
                    label.setText(format(elapsed));    
                    time=label.getText();
                    File f=new File("time.txt");
                    BufferedWriter bw;
                    try {
                        bw = new BufferedWriter(new FileWriter(f));
                        bw.write(time);
                        bw.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }    
     
                try {    
                    sleep(1);  // 1毫秒更新一次显示  
                } catch (InterruptedException e) {    
                    e.printStackTrace();    
                    System.exit(1);    
                }    
            }    
        }    
     
        // 将毫秒数格式化    
        private String format(long elapsed) {    
            int hour, minute, second, milli;    
     
            milli = (int) (elapsed % 1000);    
            elapsed = elapsed / 1000;    
     
            second = (int) (elapsed % 60);    
            elapsed = elapsed / 60;    
     
            minute = (int) (elapsed % 60);    
            elapsed = elapsed / 60;    
     
            hour = (int) (elapsed % 60);    
     
            return String.format("%02d:%02d:%02d:%03d", hour, minute, second, milli);    
        }   

(4)柱状图功能:

public class BarGraph extends JPanel 
{
    private int x;
    private static int length ; 
    int i=0;
    public int[] count;
    ArrayList<JLabel> label = new ArrayList<JLabel>();
    public BarGraph(final ArrayList<String> summer) 
    {
        length = summer.size();
        count = new int[length];
        System.out.print(length);
        this.setLayout(null);
        for(int i=0;i<summer.size();i++)
        {
            count[i] = Integer.parseInt(summer.get(i));    
        }
        for(int i=1;i<summer.size();i=i+2)
        {
            JLabel  Label = new JLabel("柱状图",JLabel.LEFT);
            Label.setFont(new Font("SansSerif", Font.BOLD + Font.ITALIC, 18));
            Label.setBounds(30+(i-1)*30, 610, 60,50);
            JLabel  Label2 = new JLabel(count[i]+"",JLabel.CENTER);
            Label2.setFont(new Font("SansSerif", Font.BOLD + Font.ITALIC, 18));
            Label2.setBounds(25+(i-1)*30, 555-6*count[i], 60,50);
            label.add(Label);
            label.add(Label2);
            this.add(label.get(i-1));
            this.add(label.get(i));  
        }
    } 
     protected void paintComponent(Graphics g) 
     {
         int x=10;
         g.setColor(Color.red);
         for (int i = 0; i < count.length; i++) 
         {   
             g.fillRect(x, 600-6*count[i], 30,6*count[i] );
             x += 30; 
         }
     }
}

D:程序运行:程序运行时每个功能界面截图。

(1)语言切换:

(2)点击“整数运算”按钮以后,随机产生20个算式,并且存在result文本文档中,同时将单独的计算结果存在result1文档中。如下图所示:

(3)计时。点击“计时”按钮,开始计时,当答案输入完毕时,提交答案,显示得分。计时器具有清零、暂停等按钮。

(4)柱状图

 

第一轮计算

 

第二轮, 再次点击“整数运算”按钮,将上一轮的文本框清空,进行再一轮运算。

将以上两轮的得分存在一个ArrayList数组中,作为绘制柱状图的参数

E:描述结对的过程,提供两人在讨论、细化和编程时的结对照片(非摆拍)

  由于我们采用的是分工合作的方法完成项目,彼此不熟悉彼此的代码风格,两个人也没有花时间去讨论类与类之间的关系,只是画了一个初期完成项目的思维导图就开始各做个的了,再花一天时间一起完善代码。在这期间,队友给我带来了很多的新思路,但同时呢,也出现过两个人彼此误导,在长时间编程以后两个人都陷入了错误之中。两个人也都在磨合之中,逐渐提高了Java的编程能力。

F:提供此次结对作业的PSP:

PSP2.1

任务内容

计划共完成需要的时间(min)

实际完成需要的时间(min)

Planning

计划

8

6

·       Estimate

·  估计这个任务需要多少时间,并规划大致工作步骤

8

6

Development

开发

82

88

··       Analysis

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

6

10

·       Design Spec

·  生成设计文档

5

6

·       Design Review

·  设计复审 (和同事审核设计文档)

4

6

·       Coding Standard

  代码规范 (为目前的开发制定合适的规范)

3

3

·       Design

  具体设计

10

12

·       Coding

  具体编码

36

21

·       Code Review

·  代码复审

7

9

·       Test

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

13

21

Reporting

报告

9

6

··       Test Report

·  测试报告

3

2

·       Size Measurement

  计算工作量

2

1

·       Postmortem & Process Improvement Plan

·  事后总结 ,并提出过程改进计划

3

3

G:请使用汉堡评价法给你的小伙伴一些点评

  首先,我要谢谢我的小伙伴,我觉得她是一个能静下心来的菇凉,欣赏她的能在一堆BUG中认真调试的心境,这一点非常值得我学习。其次,我认为我们的编码习惯真的是有待改进,希望在这一点上我们可以一起成长。最后,希望你和我都能继续保持这种不断自学的习惯和能力,一起加油!ps:很喜欢你的紫色背景。

H:结对编程真的能够带来1+1>2的效果吗?通过这次结对编程,请谈谈你的感受和体会。

  结对编程真的能有1+1>2效果,前提是两个人能进行充分的交流,并能很好的进行协调,能及时纠正对方的错误或知识上的误区。正如小伙伴在博客中讲的“自己在编写代码的时候,很容易陷入错误的思路之中,此时队友就可以在一旁点醒自己。两个人编程可以取长补短,相互补充不知道的知识,同时也因为分工合作的原因,不自觉地会将代码规范,认真地将自己写的代码部分注释好意思,并且给队友讲解,在这个过程中,自己对自己的要求高了,知识记忆也加深了。当然了,凡事都要两面性,在与队友的磨合时,花费了很长的时间,也面临了与队友的时间冲突问题,但这些都是可以一一克服的”。

  还有就是一定要有不断自学的能力,我觉得这是非常重要的。希望自己能保持一种不断学习的状态,继续我接下来的学习道路。

 

posted @ 2018-04-04 00:07  hyt_6233  阅读(258)  评论(3编辑  收藏  举报