Github项目链接:https://github.com/shoulder01/Fouroperation.git

一、项目相关要求

1. 使用 -n 参数控制生成题目的个数(实现)

2.使用 -r 参数控制题目中数值(自然数、真分数和真分数分母)的范围(实现)

3.生成的题目中计算过程不能产生负数,也就是说算术表达式中如果存在形如e1 − e2的子表达式,那么e1 ≥ e2(实现)

4.生成的题目中如果存在形如e1 ÷ e2的子表达式,那么其结果应是真分数(未实现)

5.每道题目中出现的运算符个数不超过3个。(实现)

6. 程序一次运行生成的题目不能重复(未实现)

7.在生成题目的同时,计算出所有题目的答案,并存入执行程序的当前目录下的Answers.txt文件(未实现)

8. 程序应能支持一万道题目的生成。(实现)

9. 程序支持对给定的题目文件和答案文件(未实现),判定答案中的对错并进行数量统计(实现)

二、PSP

PSP2.1

Personal Software Process Stages

预估耗时(分钟)

实际耗时(分钟)

Planning

计划

60

40

· Estimate

· 估计这个任务需要多少时间

1440

1520

Development

开发

1250

1330

· Analysis

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

90

60

· Design Spec

· 生成设计文档

100

· Design Review

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

60

40

· Coding Standard

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

30

20

· Design

· 具体设计

60

60

· Coding

· 具体编码

500

500

· Code Review

· 代码复审

30

30

· Test

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

250

300

Reporting

报告

90

90

· Test Report

· 测试报告

50

50

· Size Measurement

· 计算工作量

30

20

· Postmortem & Process Improvement Plan

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

90

90

合计

1400

1460

三、代码

import java.util.Scanner;
public class Fouroperation{
private static Scanner scanner;
public static void main(String[] args) {
int x,y,i,a1,q,d1=0;
int rigthN=0,wrongN=0;
String g = null;
String d = null;
System.out.println("请选择式子类型:1、整数,2、分数");
scanner=new Scanner(System.in);
a1=scanner.nextInt();
if(a1==1){ //整数运算
System.out.println("请输入题目的数量:");
scanner=new Scanner(System.in);
x=scanner.nextInt();
int rigthanswer[]=new int [x];
int youranswer[]=new int [x];
System.out.println("请输入数值的最大范围:");
y=scanner.nextInt();
for(i=0;i<x;i++){
int a=(int)(Math.random()*y);//随机生成一个整数
int b=(int)(Math.random()*y);//随机生成一个整数
int c=(int)(Math.random()*3);//随机生成一个0-3的整数,生成运算符
if(c==0)
{//加法
d1=a+b;
System.out.print(a+"+"+b+"=");
}
if(c==1)
{//减法
if(a>=b){
d1=a-b;
System.out.print(a+"-"+b+"=");
}else {d1=b-a;
System.out.print(b+"-"+a+"=");
}
}
if(c==2)
{//乘法
d1=a*b;
System.out.print(a+"*"+b+"=");
}
if(c==3)
{//除法
d1=a/b;
System.out.print(a+"/"+b+"=");
}
System.out.println("请输入你的答案:");
q=scanner.nextInt();
youranswer[i]=q;
rigthanswer[i]=d1;
}
System.out.print("\n");
System.out.println("显示答案请输:1");
if(scanner.nextInt()==1){
System.out.println("正确答案:\n");
for(i=0;i<x;i++){
System.out.print(rigthanswer[i]);
System.out.println("\t");
if(youranswer[i]==rigthanswer[i]){
rigthN++;
}else{
wrongN++;
}
}
System.out.print("答对"+rigthN+"题");
System.out.print("答错"+wrongN+"题");
}
}
if(a1==2){ //分数运算
int M,Z;
int x1,x2,B,m1,m2;
System.out.println("请输入题目的数量: ");
scanner=new Scanner(System.in);
x=scanner.nextInt();
String rigthanswer[]=new String [x]; //正确答案数组
String youranswer[]=new String [x]; //做答答案数组
System.out.println("请输入分母数值的最大范围: ");
B=scanner.nextInt();
for(i=0;i<x;i++){
m1=1+(int)(Math.random()*B);//随机生成一个分母
x1=1+(int)(Math.random()*m1);//生成一个比分母小的分子
m2=1+(int)(Math.random()*B);//随机生成一个分母
x2=1+(int)(Math.random()*m2);//生成一个比分母小的分子
int c=(int)(Math.random()*3);//随机生成一个0-3的整数生成运算符
if(c==0){ //加法
Z=x1*m2+x2*m1;
M=m1*m2;
d=simplification(Z,M);
System.out.print(x1+"/"+m1+"+"+x2+"/"+m2+"=");
}
if(c==1){ //减法
Z=x1*m2-x2*m1;
M=m1*m2;
d=simplification(Z,M);
System.out.print(x1+"/"+m1+"-"+x2+"/"+m2+"=");
}
if(c==2){ //乘法
Z=x1*x2;
M=m1*m2;
d=simplification(Z,M);
System.out.print(x1+"/"+m1+"*"+x2+"/"+m2+"=");
}
if(c==3){ //除法
Z=m1*x2;
M=m2*x1;
d=simplification(Z,M);
System.out.print(x1+"/"+m1+"/"+x2+"/"+m2+"=");
}
System.out.println("请输入你的答案:");
g=scanner.next();
youranswer[i]=g;//输进自己的答案装到数组中
rigthanswer[i]=d;//将正确答案装到数组中
}
System.out.print("\n");
System.out.println("显示答案请输入:1");
if(scanner.nextInt()==1){
for(i=0;i<x;i++){
System.out.print(rigthanswer[i]);
System.out.println("\t");
if(youranswer[i]==rigthanswer[i]){
rigthN++;//计算做对的题目
}else{
wrongN++;//计算做错的题目
}
}
System.out.print("答对"+rigthN+"题");
System.out.print("答错"+wrongN+"题");
}
}
}
public static String simplification(int a,int b){//把分数结果化简
int y = 1;
for(int i=a;i>=1;i--){
if(a%i==0&&b%i==0){
y = i; //求得最小公约数
break;
}
}
int z = a/y;
int m = b/y;
if(z==0) {
return "0";
}
if(z==m){//分子分母相同情况直接输出整数
return ""+z;
}
return ""+z+"/"+m;//若分子分母不同,则输出分数形式
}
}

四、运行结果

五、总结

这次任务要求是两个人完成,但由于自己基础较差,所以就自己一个人尝试完成。

这次任务有很多功能没有实现,只是实现了一些基本的功能,但这些功能都没有很完善。

在做这个任务的过程中,也是在慢慢捡起学过的java知识,虽然还是没有很大的进步,但还是有一些收获。以后还是会继续努力。

java实现自动生成四则运算的更多相关文章

  1. 根据wsdl文件,Java工程自动生成webservice客户端调用

    根据wsdl文件,Java工程自动生成webservice客户端调用 1,工具:带有webservice插件的myeclips 2,步骤: (1),新建一个Java工程:relationship (2 ...

  2. 20194651—自动生成四则运算题第一版报告chris

    1.需求分析: (1)自动生成四则运算算式(+ - *  /),或两则运算(+  -). (2)剔除重复算式. (3)题目数量可定制. (4)相关参数可控制. (5)生成的运算题存储到外部文件中. 2 ...

  3. java实现自动生成小学四则运算——朱庭震,詹祺豪

    组员:朱庭震,詹祺豪 Github地址:https://github.com/ztz1998/second/tree/master 1题目:实现一个自动生成小学四则运算题目的命令行程序. 2说明: 自 ...

  4. 自动生成四则运算题目(C语言)

    Github项目地址:https://github.com/huihuigo/expgenerator 合作者:马文辉(3118005015).卢力衔(3118005013) 项目简介 1题目:实现一 ...

  5. 结对项目 实现自动生成四则运算题目的程序 (C++)

    本次作业由 陈余 与 郭奕材 结对完成 零.github地址: https://github.com/King-Authur/-Automatically-generate-four-arithmet ...

  6. Java代码自动生成,生成前端vue+后端controller、service、dao代码,根据表名自动生成增删改查功能

    本项目地址:https://github.com/OceanBBBBbb/ocean-code-generator 项目简介 ocean-code-generator采用(适用):     ,并使用m ...

  7. Java实例练习——java实现自动生成长度为10以内的随机字符串(可用于生成随机密码)

    package sorttest; import java.util.ArrayList; import java.util.Collections; import java.util.List; i ...

  8. C语言编程—自动生成四则运算升级版

    #include<stdio.h> #include<time.h> struct fenshu { int fenzi; int fenmu; }Fenshu[]; int ...

  9. C语言#自动生成四则运算的编程

    #include <iostream> #include <stdio.h> #include <stdlib.h> #include <time.h> ...

随机推荐

  1. 37. Sudoku Solver (Array;Back-Track)

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  2. 836. Rectangle Overlap 矩形重叠

    [抄题]: A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of i ...

  3. 关于swift语言中导入OC三方类找不到头文件的解决方法

    首先我遇到的问题是这样的: 我之前封装的OC类,我导入现在的swift工程中,然后建立桥接文件,在Swift的控制器中可以找到这个OC写的东西. 但是问题来了,当你使用cocoapods导入的OC三方 ...

  4. async与await

    在方法上可以加 async,方法体内需要有 await,没有await的话,会出现warn警告.async单独出现是没有用的. await只能出现在Task前面.await Task的后面的代码会被封 ...

  5. CentOS7下搭建基本LNMP环境,部署WordPress

    系统环境:CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64 软件版本:nginx-1.12.2.tar.gz php 7.1.11 ...

  6. 201621123008 《Java程序设计》第二周学习总结

    1. 本周学习总结 通过查询API掌握了一下几种类的基本用法: String类 StringBuilder类 ArrayList类 BigInteger类 BigDecimal类 Arrays类 认知 ...

  7. WCF数据契约代理和已知类型的使用

    using Bll; using System; using System.CodeDom; using System.Collections.Generic; using System.Collec ...

  8. wcf服务契约的重载

    a. 服务端 .服务端 契约用OperationContract的Name实现重载 using System; using System.Collections.Generic; using Syst ...

  9. 微信分享 apicloud方式 中遇到的坎

    1  appid填错了. 2 图片地址没写对,可能因为拼写问题,图片不存在 3 图片大小有限制.不能太大.

  10. 移动文件读/写指针----lseek

    头文件:#include<sys/types.h>.#include<unistd.h> 函数原型:off_t lseek(int fildes,off_t offset,in ...