• 小学生求求你别折磨程序员


    结对编程

    学号1:211606374 姓名:南千昊 学号2:211606357 姓名:陈远军

    一、预估与实际

    PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟)
    Planning 计划
    • Estimate • 估计这个任务需要多少时间 1200 1680
    Development 开发
    • Analysis • 需求分析 (包括学习新技术) 80 120
    • Design Spec • 生成设计文档 40 60
    • Design Review • 设计复审 50 60
    • Coding Standard • 代码规范 (为目前的开发制定合适的规范) 60 60
    • Design • 具体设计 120 230
    • Coding • 具体编码 700 1000
    • Code Review • 代码复审 50 70
    • Test • 测试(自我测试,修改代码,提交修改) 10 10
    Reporting 报告
    • Test Repor • 测试报告 20 30
    • Size Measurement • 计算工作量 10 10
    • Postmortem & Process Improvement Plan • 事后总结, 并提出过程改进计划 30 30
    合计 1680

    二、需求分析

    我通过百度搜索的方式了解到,小学三年级数学有如下的几个特点:

    • 特点1 运算符在2~4个
    • 特点2 可以加括号运算
    • 特点3 除法运算除数不能为0,不能有余数
    • 特点4 减法运算的结果不能有负数
    • 特点5 混合运算结果不能是小数
    • 特点6 除法运算不能出现小数,只能是整数

    经过分析,我认为,这个程序应当:

    • 使用的数字小于100且大于0的整数
    • 被减数不能小于减数
    • 有除法尽量可以整除

    三、设计

    1. 设计思路

    说明你如何设计这个程序

    比如:

    • 这个程序有1个类,在main方法中直接通过构造函数调用
    • Math.random是可以生成随机数的关键
    • 要将字符串转换为字节流来存入txt文本
    • 找到一些输入错误的bug
    • args[0].equals("-n") ,来确认-n ,来确定输入参数
      -args[0].equals("-grade"),来确认-grade,来确定输入参数

    2. 实现方案

    暂时用穷举法勉强给客户使用

    四、编码

    • 用args数组来实现从命令行中接收参数,否则不能直接输入参数运行
    • if(args[0].equals("-n")) ,获取第一个参数,判断是否和-n一致。
    • 用Math.random进行随机数的生成
    • 将括号内的数字先得出结果,在和另一个数相乘得到结果

    1. 调试日志

    在加减乘除计算中无法合理顺序计算结果
    用穷举法慢慢尝试
    -n 和-grade 对应arg[]的位置弄错了 第一个位置是arg[0]第四个位置是arg[3]

    2. 关键代码

    
    /*
    
    ** Create or reuse a zero-terminated string, first checking in the
    
    ** cache (using the string address as a key). The cache can contain
    
    ** only zero-terminated strings, so it is safe to use 'strcmp' to
    
    ** check hits.
    
    */
    if(args[0].equals("-n")) 
    	    {
    			c[0] = Integer.parseInt(args[1]);
    			c[1] = Integer.parseInt(args[3]);
    			flag2=1;
    			}
    			else if(args[0].equals("-grade"))
    			{
    				c[0] = Integer.parseInt(args[3]);
    				c[1] = Integer.parseInt(args[1]);
    				flag2=2;
    			}
       
    else if(c[1]==3) {
    		 for(i=1;i<=c[0];i++) {
    			 fuhao=(int)(Math.random()*8);
    				if(fuhao==0) {
    					a = (int)(Math.random()*100+1);
    					b = (int)(Math.random()*100+1);
    					d = (int)(Math.random()*100+1);
    		         int answer=a*b+d;
    		         System.out.println("( "+i+" )"+a+" × "+b+" + "+d);
    		         timu[i-1]="( "+i+" )"+a+" × "+b+" + "+d;
    		         daan[i-1]="( "+i+" )"+a+" × "+b+" + "+d+" = "+answer;
    		         byte[] ti =timu[i-1].getBytes();
    		         byte[] da =daan[i-1].getBytes();
    		         byte[] h=huanhang.getBytes();
    		         u.write(ti);
    		         u.write(h);
    				}
    				if(fuhao==1) {
    					 a = (int)(Math.random()*100+1);
    					 b = (int)(Math.random()*100+1);
    					 d = (int)(Math.random()*100+1);
    					 e = (int)(Math.random()*100+1);
    					int answer=a*b+d-e;
    			         System.out.println("( "+i+" ) "+a+" × "+b+" + "+d+" - "+e);
    			         timu[i-1]="( "+i+" ) "+a+" × "+b+" + "+d+" - "+e;
    			         daan[i-1]="( "+i+" ) "+a+" × "+b+" + "+d+" - "+e+" = "+answer;
    			         byte[] ti =timu[i-1].getBytes();
    			         byte[] da =daan[i-1].getBytes();
    			         byte[] h=huanhang.getBytes();
    			         u.write(ti);
    			         u.write(h);
    				}
    				if(fuhao==2) {
    					 b = (int)(Math.random()*100+1);
    					 a = 3*b;
    					 d = (int)(Math.random()*100+1);
    					 e = (int)(Math.random()*100+1);
    					int answer=a/b+d-e;
    			         System.out.println("( "+i+" ) "+a+" ÷ "+b+" + "+d+" - "+e);
    			         timu[i-1]="( "+i+" ) "+a+" ÷ "+b+" + "+d+" - "+e;
    			         daan[i-1]="( "+i+" ) "+a+" ÷ "+b+" + "+d+" - "+e+" = "+answer;
    			         byte[] ti =timu[i-1].getBytes();
    			         byte[] da =daan[i-1].getBytes();
    			         byte[] h=huanhang.getBytes();
    			         u.write(ti);
    			         u.write(h);
    				}
    				if(fuhao==3) {
    					 b = (int)(Math.random()*100+1);
    					 a = 6*b;
    					 d = (int)(Math.random()*100+1);
    					 e = (int)(Math.random()*100+1);
    					 f = (int)(Math.random()*100+1);
    					int answer=a/b+d-e+f;
    			         System.out.println("( "+i+" ) "+a+" ÷ "+b+" + "+d+" - "+e+" + "+f);
    			         timu[i-1]="( "+i+" ) "+a+" ÷ "+b+" + "+d+" - "+e+" + "+f;
    			         daan[i-1]="( "+i+" ) "+a+" ÷ "+b+" + "+d+" - "+e+" + "+f+" = "+answer;
    			         byte[] ti =timu[i-1].getBytes();
    			         byte[] da =daan[i-1].getBytes();
    			         byte[] h=huanhang.getBytes();
    			         u.write(ti);
    			         u.write(h);				
    				}
    				if(fuhao==4) {
    					 b = (int)(Math.random()*100+1);
    					 a = 2*b;
    					 d = (int)(Math.random()*100+1);
    					 e = (int)(Math.random()*100+1);
    					 f = (int)(Math.random()*100+1);
    					int answer=a/b*d-e+f;
    			         System.out.println("( "+i+" ) "+a+" ÷ "+b+" × "+d+" - "+e+" + "+f);
    			         timu[i-1]="( "+i+" ) "+a+" ÷ "+b+" × "+d+" - "+e+" + "+f;
    			         daan[i-1]="( "+i+" ) "+a+" ÷ "+b+" × "+d+" - "+e+" + "+f+" = "+answer;
    			         byte[] ti =timu[i-1].getBytes();
    			         byte[] da =daan[i-1].getBytes();
    			         byte[] h=huanhang.getBytes();
    			         u.write(ti);
    			         u.write(h);				
    				} 
    				if(fuhao==5) {
    					 b = (int)(Math.random()*100+1);
    					 a = 3*b;
    					 d = (int)(Math.random()*100+1);
    					 e = (int)(Math.random()*100+1);
    					 int l=d-e;
    					 int answer=l+a/b;
    			         System.out.println("( "+i+" ) "+a+" ÷ "+b+" + "+"( "+d+" - "+e+" )");
    			         timu[i-1]="( "+i+" ) "+a+" ÷ "+b+" + "+"( "+d+" - "+e+" )";
    			         daan[i-1]="( "+i+" ) "+a+" ÷ "+b+" + "+"( "+d+" - "+e+" )"+" = "+answer;
    			         byte[] ti =timu[i-1].getBytes();
    			         byte[] da =daan[i-1].getBytes();
    			         byte[] h=huanhang.getBytes();
    			         u.write(ti);
    			         u.write(h);
    				}
    				if(fuhao==6) {
    					 a = (int)(Math.random()*100+1);
    					 b = (int)(Math.random()*100+1);
    					 d = (int)(Math.random()*100+1);
    					 e = (int)(Math.random()*100+1);
    					 int l=+b+d+e;
    					int answer=a*l;
    			         System.out.println("( "+i+" ) "+a+" × "+"( "+b+" + "+d+" + "+e+" )");
    			         timu[i-1]="( "+i+" ) "+a+" × "+"( "+b+" + "+d+" + "+e+" )";
    			         daan[i-1]="( "+i+" ) "+a+" × "+"( "+b+" + "+d+" + "+e+" )"+" = "+answer;
    			         byte[] ti =timu[i-1].getBytes();
    			         byte[] da =daan[i-1].getBytes();
    			         byte[] h=huanhang.getBytes();
    			         u.write(ti);
    			         u.write(h);
    				}if(fuhao==7) {
    					 a = (int)(Math.random()*100+1);
    					 b = (int)(Math.random()*100+1);
    					 d = (int)(Math.random()*100+1);
    					 e = (int)(Math.random()*100+1);
    					 int l=a+b;
    					 int z=d+e;
    					int answer=z*l;
    			         System.out.println("( "+i+" ) "+"( "+a+" + "+b+" )"+" * "+"( "+d+" + "+e+" )");
    			         timu[i-1]="( "+i+" ) "+"( "+a+" + "+b+" )"+" * "+"( "+d+" + "+e+" )";
    			         daan[i-1]="( "+i+" ) "+"( "+a+" + "+b+" )"+" * "+"( "+d+" + "+e+" )"+" = "+answer;
    			         byte[] ti =timu[i-1].getBytes();
    			         byte[] da =daan[i-1].getBytes();
    			         byte[] h=huanhang.getBytes();
    			         u.write(ti);
    			         u.write(h);
    				}
    				
    	}
    

    3. 代码规范

    请给出本次实验使用的代码规范:

    • 如果有异常进行手动处理,不抛出,并人工检查代码是否符合规范

    • 左大括号前不换行。
      左大括号后换行。
      右大括号前换行。
      右大括号后还有 else 等代码则不换行;表示终止的右大括号后必须换行。

    • 采用4个空格缩进,禁止使用tab字符

    五、测试

    测试输入:java MathExam6374 -n 5000 -grade 1测试结果:请输入1-400之间的题目数,否则题目重复,请重新输入 预期结果:符合测试
    测试输入:java MathExam6374 -n -1 -grade 1 测试结果:输入的题目数请大于1,请重新输入 预期结果:符合测试
    测试输入:java MathExam6374-n 10 -grade 4 测试结果:本程序仅支持1年级和2年级和3年级,请重新输入 预期结果:符合测试
    测试输入:java MathExam6374 -n 100 -grade 2 测试结果:请输入1-81之间的题目数,否则题目重复,请重新输入 预期结果:符合测试
    测试输入:java MathExam6374 -grade 5000 -, 1测试结果:请输入1-400之间的题目数,否则题目重复,请重新输入 预期结果:符合测试
    测试输入:java MathExam6374 -grade -1 -n 1 测试结果:输入的题目数请大于1,请重新输入 预期结果:符合测试
    测试输入:java MathExam6374-grade 10 -n 4 测试结果:本程序仅支持1年级和2年级和3年级,请重新输入 预期结果:符合测试
    测试输入:java MathExam6374 -grade 100 -n 2 测试结果:请输入1-81之间的题目数,否则题目重复,请重新输入 预期结果:符合测试

    六、总结

    这次代码对我来说应该是地狱模式,我只能说给我别人的答案我也看不懂,虽然刚刚弄懂逆波兰函数和调度法,但是留给我们的时间已经不够了,暂时先交一个穷举法的程序,客户用起来应该也不会有太多差别,一下子难度加大,很难适应,只能慢慢突破自己了
    还好是结对作业,彼此互相鼓励,才能坚持下去,至少写出了给客户能满意用的程序。

  • 相关阅读:
    deleted
    deleted
    HDU
    FZU 1901 Period II(KMP中的next)题解
    HDU 3374 String Problem(最大最小表示+KMP)题解
    HDU 4300 Clairewd’s message(扩展KMP)题解
    POJ 2923 Relocation(状压DP+01背包)题解
    HDU 4272 LianLianKan (状压DP+DFS)题解
    POJ 1185 炮兵阵地(状压DP)题解
    POJ
  • 原文地址:https://www.cnblogs.com/nxq7/p/9672183.html
Copyright © 2020-2023  润新知