个人工作流程计应192六组郭梦园

PSP计划表

PSP阶段

预计花费时间(小时) 实际花费时间
计划 1 2
明确需求和其他相关因素,估计每个阶段的时间成本 1 2
开发 35 30
需求分析 2 2
代码规范 2 1
具体设计 3 4
具体编码 5 7
代码复审 3 2

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

2 3

需求分析:


程序可接收一个输入参数n,然后随机产生n道加减乘除练习题,每个数字在 0 和 100 之间。

同时,由于小学生没有分数与负数的概念,你所出的练习题在运算过程中不得出现负数与非整数,比如不能出 3/5+2=2.6,2-5+10=7等算式。

 

功能分析:

输入需要产生的题目个数。

随机生成一个个数字号的表达式。

屏幕依次显示产生的题目以及计算结果。

最后将运算表达式和计算结果显示出来。

 代码:

/**

* @Title: shu.java
* @Description: TODO
* @author 郭梦园
*/
package a;

/**
* @ClassName: shu
* @Description: TODO
* @author 郭梦园
*/
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.OutputStream;
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

public class shengcheng {
public static void main(String[] args) throws IOException {
File file= new File("C:\\Users\\ASUS\\Desktop\\Java\\2020 3 10\\src\\a\\result.txt");
PrintStream ps = new PrintStream("C:\\Users\\ASUS\\Desktop\\Java\\2020 3 10\\src\\a\\shengcheng.txt");
Writer out = new FileWriter(file);
int c;
Scanner sc=new Scanner(System.in);
System.out.print("请输入题目个数:");
int tg=sc.nextInt();
System.out.print("请输入操作数的范围(如 100,1000等):");
int tf=sc.nextInt();
System.out.println("请选择是否有负数:1:有 0:没有");
int zf=sc.nextInt();
System.out.println("请选择是否包含*或者/:2:否 4:是 ");
int fu=sc.nextInt();
System.setOut(ps);
for(int i=0;i<tg;i++) {//循环控制题目个数

//第一个操作数的选择
int a=(int)(Math.random()*tf);

if(zf==1) {//有负数
int p=(int) (Math.random()*2);
switch(p) {
case 0:a=a*(-1);//取负数
System.out.print(a);break;
case 1:
System.out.print(a);break;
}
}
if(zf==0)System.out.print(a);
else{//选择两个字符‘+’‘-’
int k=(int)(Math.random()*2);
switch(k) {//随机选择运算符
case 0:System.out.print("+");
break;
case 1:System.out.print("-");
break;
}
int b=(int)(Math.random()*(tf-a));
while(b>a)b=(int)(Math.random()*(tf-a));
if(zf==1) {//有负数
int p=(int) (Math.random()*2);
switch(p) {
case 0:b=b*(-1);//取负数
System.out.print(b);break;
case 1:
System.out.print(b);break;
}
}
else System.out.print(b);
System.out.println("=");
String huanhang="\r\n";
if(k==0)
{
c=a+b;
out.write( Integer.toString(c)+huanhang);
}
else {c=a-b; out.write( Integer.toString(c)+huanhang);}
}
if(fu==4) {//四个字符的‘+’‘-’‘*’‘/’
int k=(int)(Math.random()*4+1);
switch(k) {//随机选择运算符
case 1:System.out.print("+");break;
case 2:System.out.print("-");break;
case 3:System.out.print("*");break;
case 4:System.out.print("/");break;
}

//第二个操作数的选择
int b=(int) (Math.random()*tf+1);

if(zf==1) {//有负数
int p=(int) (Math.random()*2);
switch(p) {
case 0:b=b*(-1);//取负数
System.out.print(b);break;
case 1:
System.out.print(b);break;
}
}
if(zf==0) System.out.print(b);
System.out.println("=");
if(k==1) {
c=a+b;out.write(c);
}
if(k==2) {
c=a-b;out.write(c);
}
if(k==3) {
c=a*b;out.write(c);
}
if(k==4) {
c=a/b;out.write(c);
}
}
}out.close();
}
}

代码实现:

 

posted @ 2021-04-11 14:13  智凯义  阅读(83)  评论(0)    收藏  举报