小学生口算题卡程序——计应193第五组赵晓明

计划:

能够做出实现加减乘除的四则运算程序,基本实现所有四则运算的需求。

需求分析:

能够实现数的加减乘除,程序运行时能够报绿条,实现加减乘除的正常运行,并计算成绩得分。

具体设计:

编写实现类,可以选择年级,里边定义要用到加减乘除四个方法,可以自由选择做题的类型和数量,

并可以实现成绩的计算,并定义相关的算法完成需求。

具体代码:

  1 package ym;
  2 
  3 import java.util.Scanner;
  4 import java.lang.String;
  5 import java.lang.Math; 
  6 
  7 public class CalculateGenerator2 {
  8         public static final int one = 1;
  9         public static final int two = 2;
 10         public static int score = 0;
 11         public static void main(String args[]) {
 12             int choose,clas,n,result, x, y,score=0;
 13             
 14             Scanner sr=new Scanner(System.in);
 15             System.out.println("欢迎使用小学四则运算系统");
 16             System.out.println("请在1~4年级中选择");
 17             clas=sr.nextInt();
 18             while(true) {
 19             if (clas==1|clas==2)
 20             {
 21                 ONE();
 22                 break;
 23             }
 24             
 25             if (clas==3|clas==4)
 26             {
 27                 TWO();
 28                 break;
 29             }
 30             
 31         }    
 32     }
 33         public static void menu1() {
 34             System.out.println("1---------加法");
 35             System.out.println("2---------减法");
 36             System.out.println("3---------退出");
 37             System.out.println("请输入你的选项:");
 38         }
 39         public static void menu2() {
 40             System.out.println("1---------加法");
 41             System.out.println("2---------减法");
 42             System.out.println("3---------乘法");
 43             System.out.println("4---------除法");
 44             System.out.println("5---------退出");
 45             System.out.println("请输入你的选项:");
 46         }
 47         public static int ADD() {
 48             int choose,clas,n,result, x, y,score=0;
 49             
 50             Scanner sr=new Scanner(System.in);
 51             
 52             System.out.println("这里是加法运算,请你输入要做题目数量");
 53             n=sr.nextInt();
 54             while(n>0) {
 55                 x=(int)(Math.random()*10);
 56                 y=(int)(Math.random()*10);
 57                 System.out.print(x+"+"+y+"=");
 58                 result=sr.nextInt();
 59                 if(result==(x+y)) {
 60                     System.out.println("回答正确");
 61                     score++;
 62                 }else {
 63                     System.out.println("回答错误,正确答案为"+(x+y));
 64                 }
 65                 n--;
 66             }
 67             return score;
 68         }
 69         
 70         public static int SUB() {
 71             int choose,clas,n,result, x, y,score=0;
 72             
 73             Scanner sr=new Scanner(System.in);
 74             
 75             System.out.println("这里是减法运算,请你输入要做题目数量");
 76             n=sr.nextInt();
 77             while(n>0) {
 78                 x=(int)(Math.random()*100);
 79                 y=(int)(Math.random()*100);
 80                 if(x<y) {
 81                     System.out.print(y+"-"+x+"=");
 82                     result=sr.nextInt();
 83                     if(result==(y-x)) {
 84                         System.out.println("回答正确,你真棒!");
 85                         score++;
 86                     }else {
 87                         System.out.println("回答错误,正确答案为"+(y-x));
 88                     }
 89                 }else {
 90                     System.out.print(x+"-"+y+"=");
 91                     result=sr.nextInt();
 92                     if(result==(x-y)) {
 93                         System.out.println("回答正确,你真棒!");
 94                         score++;
 95                     }else {
 96                         System.out.println("回答错误,正确答案为"+(x-y));
 97                     }
 98                 }
 99                 n--;
100             }
101             return score;
102         }
103 
104         public static int MULTI() {
105             int choose,clas,n,result, x, y,score=0;
106             
107             Scanner sr=new Scanner(System.in);
108             
109             System.out.println("这里是乘法运算,请你输入要做题目数量");
110             n=sr.nextInt();
111             while(n>0) {
112                 x=(int)(Math.random()*10);
113                 y=(int)(Math.random()*10);
114                 System.out.print(x+"*"+y+"=");
115                 result=sr.nextInt();
116                 if(result==(x*y)) {
117                     System.out.println("回答正确,你真棒!");
118                     score++;
119                 }else {
120                     System.out.println("回答错误,正确答案为"+(x*y));
121                 }
122                 n--;
123             }
124             return score;
125         }
126         
127         public static int DIVI() {
128             int choose,clas,n,result, x, y,score=0;
129             
130             Scanner sr=new Scanner(System.in);
131             
132             int all, max;
133             System.out.println("这里是除法运算,请你输入要做题目数量");
134             n=sr.nextInt();
135             while(n>0) {
136                 x=(int)(Math.random()*10);
137                 y=(int)(Math.random()*10);
138                 all=x*y;
139                 
140                 if(y!=0) {
141                     System.out.print(all+"/"+y+"=");
142                     result=sr.nextInt();
143                     if(result==(all/y)) {
144                         System.out.println("回答正确,你真棒!");
145                         score++;
146                     }else {
147                         System.out.println("回答错误,正确答案为"+(all/y));
148                     }        
149                 }
150                 n--;
151             }
152             return score;
153         }
154        
155         public static void ONE() {
156             int choose,clas,n,result, x, y;
157             Scanner sr=new Scanner(System.in);
158             
159             while(true) {
160                 menu1();
161                 choose=sr.nextInt();
162                 
163                 switch(choose) {
164                 case 1:
165                     System.out.println("本次加法运算得分是"+ADD());
166                     break;
167                     
168                 case 2:
169                     System.out.println("本次加法运算得分是"+SUB());
170                     break;        
171                     
172                 case 3:
173                     System.out.print("退出成功.");
174                     System.exit(0);
175                 }
176             }
177         }
178         
179         public static void TWO() {
180             int choose,clas,n,result, x, y;
181             Scanner sr=new Scanner(System.in);
182             
183             while(true) {
184                 menu2();
185                 choose=sr.nextInt();
186                 
187                 switch(choose) {
188                 case 1:
189                     System.out.println("本次加法运算得分是"+ADD());
190                     break;
191                     
192                 case 2:
193                     System.out.println("本次加法运算得分是"+SUB());
194                     break;
195                     
196                 case 3:
197                     System.out.println("本次加法运算得分是"+MULTI());
198                     break;
199                     
200                 case 4:
201                     System.out.println("本次加法运算得分是"+DIVI());
202                     break;
203         
204                 case 5:
205                     System.out.print("退出成功.");
206                     System.exit(0);        
207                 }
208             }
209             
210         }
211 }

 

代码规范:

取符合命名规范的名字,以便于后期的维护,严格代码规范,写能让人看懂的代码

功能实现:

代码复审:

对代码运行进行观察,看看是否符合规范或存在报错的现象,能够正常运行,不能的话在进行改正和优化。

测试:

在测试类中看加减乘除的具体功能是否能顺利实现,不能要进行优化。

总结:

这次实现四则运算的过程我知道了要实现一个项目所需要具备的东西,以及需要多方面考虑,这次完成个人项目我对于代码的理解也更深了一步,一个项目的完成所有的步棸都要细心地做好,这样才能顺利实现预期的目标和功能。

PSP阶段

自己所花时间百分比

工程师所花时间百分比

计划

10

6

  •  明确需求和其他相关因素,估计每个阶段的时间成本

10

6

开发

80

88

  •  需求分析

6

10

  •  生成设计文档

5

6

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

4

6

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

5

3

  •  具体设计

9

12

  •  具体编码

35

21

  •  代码复审

6

9

  •  测试(自测、修改代码、修改提交)

10

21

报告

10

6

  •  测试报告

3

2

  •  计算工作量

2

1

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

5

3

posted @ 2021-04-11 11:37  Xiao旋  阅读(338)  评论(0)    收藏  举报