自动生成小学生四则运算(皮!)

                                 自动生成小学生四则运算(皮!) 

coding 地址 https://coding.net/u/smile12231/p/autoCalcilate/git

a·需求分析   

      在这个家长希望自己的小孩能够赢在起跑线的社会,通常寻找很多的练习给小学生做,所以我们就来编写一个四则运算的软件,你懂我意思吧!这个软件能够

      ①丶根据用户想要的出题量生成题目

      ②丶生成的题目包括整数和分数的加减乘除

      ③丶能够自动判断答案是否正确并给出此次的正确率

      ④丶使用 -n 参数控制生成题目的个数,例如执行下面命令将生成10个题目

b丶功能设计

      基本功能:提示用户输入想要的题目数量,并且在每昨晚一提后能直接显示对错,

      扩展功能:如果错误的话能够给出正确答案

      高级功能:首次充值六元RMB就能够真送一本小学生唐诗三百首(但是作者能力有限无法之,很难受)

c丶设计实现

      我会有java.util.Scanner;java.util.Random;这两个java类

      java.Util.Scanner;能够使程序捕捉到用户输入的题目量

      java.util.Random;能够让程序自动生成整数,在经过设计者的巧夺天工处理实现自动生成题目

d丶代码说明

 1 //自动生成题目
 2 package add_sub_mul_div;
 3 
 4 import java.util.Random;
 5 
 6 public class Create_Question {
 7     public void C_Q(String m){
 8         Int_Method im=new Int_Method();
 9         Flo_Method fm=new Flo_Method();
10         int n=Integer.parseInt(m.trim());
11         int e=0,f=0;
12         for(int i=0;i<n;i++){
13             Random r=new Random();
14 //            int c=r.nextInt(4);
15             int c=3;
16             //随机生成一个数0是整数加减乘除1是分数加减乘除
17 //            int i1=r.nextInt(2);
18             int i1=1;
19             if(i1==0){
20                 //随机生成一个数0-3决定做加还是减。。。
21                 if(c==0){
22                     int a=im.Add(r.nextInt(10), r.nextInt(10)) ;
23                     im.Add1(a);
24                     e=e+im.i;
25                 }else if (c==1){ 
26                     int a=im.Sub(r.nextInt(10), r.nextInt(10));
27                     im.Sub1(a);
28                     e=e+im.i;
29                 }else if(c==2){
30                     int a=im.Mul(r.nextInt(10), r.nextInt(10));
31                     im.Mul1(a);
32                     e=e+im.i;
33                 }else if(c==3){
34                     String a=im.Div(r.nextInt(10), r.nextInt(10));
35                     im.Div1(a);
36                     e=e+im.i;
37                 }
38             }else if(i1==1){
39                 if(c==0){
40                     String s=fm.Add(r.nextInt(10)+1,r.nextInt(10)+1,r.nextInt(10)+1,r.nextInt(10)+1 );
41                     if(fm.Add1(s)){
42                         f=f+1;
43                     }
44                     
45                 }
46                 else if(c==1){
47                     String s=fm.Sub(r.nextInt(10)+1,r.nextInt(10)+1,r.nextInt(10)+1,r.nextInt(10)+1 );
48                     
49                     f=f+fm.Sub1(s);
50                 }
51                 else if(c==2){
52                     String s=fm.Mul(r.nextInt(10)+1,r.nextInt(10)+1,r.nextInt(10)+1,r.nextInt(10)+1 );
53                 
54                     f=f+fm.Mul1(s);
55                 }
56                 else if(c==3){
57                     String s=fm.Div(r.nextInt(10)+1,r.nextInt(10)+1,r.nextInt(10)+1,r.nextInt(10)+1 );
58                     
59                     f=f+fm.Div1(s);
60                 }
61                     
62             }
63                 
64         }
65         int result=e+f;
66         System.out.println("小样你的正确率:  "+(1.0*result)/n*100+"%");
67         
68     }
69 }

 

 1    //实现整数加法的方法
 2 
 3       public int Add(int a,int b){       //闯入两个int型的整数
 4 
 5         System.out.print(a+"+"+b+"= ");//输出题目按照小学生的视角
 6 
 7         int result=(a+b);                //程序后台算出此题目的正确答案
 8 
 9         return result;              //返回答案
10       }
11 
12       //判断答案是否正确的方法
13 
14       public void Add1(int result){
15 
16         Scanner sc=new Scanner(System.in);   //新建一个Scanner类的对象sc
17         int input= sc.nextInt();          //小学生输入一个整数(答案)并且赋值给input
18 
19         if(input==result){              //如果答案正确输出做对了
20 
21         System.out.println("答对了 ");
22         this.i=1;                  //i==1表示做对了
23         }else{                          //如果答案不正确,你知道的尽情的嘲讽
24         System.out.println("你皮任你皮 当你是瓜皮!!! 你皮任你皮 当你是瓜皮!!! 答错了 哈哈哈 哈哈哈 ");
25         this.i=0;
26         }
27       }
28 
29       //分数加法题目生成发方法
30 
31       public String Add(int a,int b,int c,int d){
32 
33       //显示题目
34         System.out.print(a+"/"+b+"+"+c+"/"+d+"=");
35         String[] str =Int_Method.Simple_Flo(a, b).split("\\/");
36         int x1=Integer.parseInt(str[0]);
37         int y1=Integer.parseInt(str[1]);
38         String[] str1=Int_Method.Simple_Flo(c, d).split("\\/");
39         int i=Integer.parseInt(str1[0]);
40         int j=Integer.parseInt(str1[1]);
41         x1=x1*j; i=i*y1; 
42         y1=y1*j; j=y1;
43         int n=x1+i;
44         int m=j;
45         return Int_Method.Simple_Flo(n, m);
46       }
47 
48       //判断分数加法题目是否正确的方法
49 
50      public boolean Add1(String s)            
Scanner sc=new Scanner(System.in);       51   String input= sc.nextLine();        //输入的转化为数字 52         String[] str=input.split("\\/"); 54         int x1=Integer.parseInt(str[0]); 55         int y1=Integer.parseInt(str[1]); 56         //化简转化的数字得到一个string 57         String s1=Int_Method.Simple_Flo(x1, y1); 58         //化简的数字string 转化成数字 59         String[] str1=s1.split("\\/"); 60         int x2=Integer.parseInt(str1[0]); 61         int y2=Integer.parseInt(str1[1]); 62         //题目给出的转化成数字 63         String[] str2=s.split("\\/"); 64         int i=Integer.parseInt(str2[0]); 65         int j=Integer.parseInt(str2[1]); 66         if(x2==i&&y2==j){ 67           System.out.println("答对了!"); 68           return true; 69         }else{ 70            System.out.println("你皮任你皮 当你是瓜皮!!! 答错了 哈哈哈!"); 71            return false; 72        } 73     } 74 75        76 77    
 1 //这是分数的除法
 2 public String Div(int a,int b,int c,int d){
 3         //显示题目
 4         System.out.print(a+"/"+b+" ÷ "+c+"/"+d+"=");
 5         String[] str =Int_Method.Simple_Flo(a, b).split("\\/");
 6         int x1=Integer.parseInt(str[0]);
 7         int y1=Integer.parseInt(str[1]);
 8         String[] str1=Int_Method.Simple_Flo(c, d).split("\\/");  //Simple_Flo 函数是用来把答案化简成最简分数
 9         int i=Integer.parseInt(str1[0]);
10         int j=Integer.parseInt(str1[1]);
11          int n=x1*j;
12          int m=y1*i;
13          return  Int_Method.Simple_Flo(n, m);
14     }
15     
16     public int Div1(String s){
17         Scanner sc=new Scanner(System.in);
18            String input= sc.nextLine();
19            //输入的转化为数字
20            String[] str=input.split("\\/");
21              int x1=Integer.parseInt(str[0]);
22              int y1=Integer.parseInt(str[1]);
23            //化简转化的数字得到一个string
24            String s1=Int_Method.Simple_Flo(x1, y1);
25            //化简的数字string 转化成数字
26            String[] str1=s1.split("\\/");
27              int x2=Integer.parseInt(str1[0]);
28              int y2=Integer.parseInt(str1[1]);
29             //题目给出的转化成数字
30              String[] str2=s.split("\\/");
31                  int i=Integer.parseInt(str2[0]);
32                  int j=Integer.parseInt(str2[1]);
33          if(x2==i&&y2==j){
34              System.out.println("答对了!");
35              return 1;
36          }
37         
38     else{
39         System.out.println("你皮任你皮 当你是瓜皮!!! 答错了 哈哈哈!");
40         System.out.println("正确答案是:"+s);
41          return 0;
42     }
43     }

 

e丶测试运行

      

      

                            

 

PSP2.1 Personal Software Process Stages Time (%) Senior Student Time (%)
Planning 计划 8
· Estimate 估计这个任务需要多少时间 8 两天
Development 开发 82 一天
· Analysis 需求分析 (包括学习新技术) 6 30min
· Design Spec 生成设计文档 5 0
· Design Review 设计复审 4 5min
· Coding Standard 代码规范 3 3
· Design 具体设计 10 0
· Coding 具体编码 36 一天
· Code Review 代码复审 7 1h
· Test 测试(自我测试,修改代码,提交修改) 13 一直在测试
Reporting 报告 9 2h
· 测试报告 3
· 计算工作量 2
· 并提出过程改进计划 3

 ps:编写代码时候没有考虑到代码的兼容性,以至于后来需要大改,而且重复的代码没有写在一个方法里,修改的时候很麻烦

e丶小结

   四则运算花费了作者一天的时间,主要是分数的四则运算花费了太多时间,分数当做字符串,的比较结果是否算对时有需要将字符串转化为整数,同时化为分子分母最简表达式最后,分子比分子,分母比分母,都相等才作对可

   有疑问时,有热心的同学帮助还有度娘,虽然编程过程中,修改的过程很复杂,但是学会了Debug方法,还是很开心的,还有java String的split用法

编程如果你感觉到了瓶颈那就是快要成神的时候了,有时候编的很烦躁的时候,我会大家TGP,看看自己的段位,喝一杯水,然后默默的开始编程咯。

posted @ 2017-03-05 18:49  沙县养猪场  阅读(327)  评论(5编辑  收藏  举报