zoukankan      html  css  js  c++  java
  • 软件工程个人作业03

    四则运算3的设计思想,源程序代码、运行结果截图、编程总结分析

    PSP2.1

    Personal Software Process Stages

    Time

    Planning

    计划

     4小时

      · Estimate

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

     3小时

    Development

    开发

     

      · Analysis

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

     

      · Design Spec

      · 生成设计文档

     

      · Design Review

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

     

      · Coding Standard

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

     

      · Design

      · 具体设计

     

      · Coding

      · 具体编码

     2小时

      · Code Review

      · 代码复审

     30分钟

      · Test

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

     5分钟

    Reporting

    报告

     

      · Test Report

      · 测试报告

     

      · Size Measurement

      · 计算工作量

     

      · Postmortem & Process Improvement Plan

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

     

     

    合计

     

    设计思想:先生成三个参与计算的随机数,两个符号,再用随机数判断是否右括号,再判断括号的位置,然后输出结果。

    源程序代码:

    
    
    package 四则运算3;
    import java.util.*;
    public class Sizeyunsuan {
        public static void main(String[] args) {
            int n = 0;
            Scanner scan = new Scanner(System.in);      
                System.out.println("请输入需要生成的题目的数量:");
                n = scan.nextInt();
                for(int i=0;i<n;){
                       shengcheng();
                        i++;
                                           }
               }
     
        public static void shengcheng(){//生成运算的式子
               int suijishu1=new Random().nextInt(101);
               int suijishu2=new Random().nextInt(101);
               int suijishu3=new Random().nextInt(101);
               //产生三个随机数
               float o=(float)suijishu1;
               float p=(float)suijishu2;
               float q=(float)suijishu3;
               //转换成float类型
               char a='0';
              char b='0';
               int fuhao1= new Random().nextInt(4);
               int fuhao2= new Random().nextInt(4);
              //产生两个随机数来决定运算符
               float jieguo=0;
               char[] fh=new char[2];
               fh[0]=a;
               fh[1]=b;
               int kuohao=new Random().nextInt(2);
               //随机数决定是否有括号
               if(kuohao==0)//没有括号
               {
                   if(b!=2&&b!=3){
                       float m=jisuan(o,fuhao1,p);
                       jieguo=jisuan(m,fuhao2,q);
                                      }
                       else if(b==2||b==3){
                           if(a==2||a==3){
                               float  m=jisuan(o,fuhao1,p);
                              jieguo=jisuan(m,fuhao2,q);
                                                }
                          else if(a==0||a==1){
                              float m=jisuan(p,fuhao2,q);
                                  jieguo=jisuan(o,fuhao1,m);
                                                         }
                                        }
                   System.out.println(suijishu1+fh(fuhao1)+suijishu2+fh(fuhao2)+suijishu3+"="+"   (答案是:"+jieguo+")");
           }
               else if(kuohao==1)//有括号
                       {
                           int weizhi=new Random().nextInt(2);//括号的位置
                           if(weizhi==0){
                               float m=jisuan(o,fuhao1,p);
                               jieguo=jisuan(m,fuhao2,q);
                               System.out.println("("+suijishu1+fh(fuhao1)+suijishu2+")"+fh(fuhao2)+suijishu3+"="+"   (答案是:"+jieguo+")");
                           }
                           else if(weizhi==1){
                               float m=jisuan(p,fuhao2,q);
                               jieguo=jisuan(o,fuhao1,m);
                               System.out.println(suijishu1+fh(fuhao1)+"("+suijishu2+fh(fuhao2)+suijishu3+")"+"="+"   (答案是:"+jieguo+")");
                    }
                 }
        }
        
        public static float jisuan(float a,int b,float c){//计算方法
            float x=0;
            if(b==0){
                x=a+c;
            }
            if(b==1){
                x=a-c;
            }
            if(b==2){
                x=a*c;
            }
            if(b==3){
                if(c==0)
                {
                    shengcheng();
                }
                else if(c!=0){
                x=a/c;            
                }
             }    
                return x;
         }
        
        public static String fh(int a){
            String x = null ;
            if(a==0){
                x="+";
            }
            else if(a==1){
                x="-";
            }
            else if(a==2){
                x="*";
            }
            else if(a==3){
                x="/";
            }
              return x;        
        }
    }
    
    
    
     

    运行结果截图:

    学生   胡泽杰

    日期   17/3/12

    教员   王建明

    程序    四则运算题目生

    日期

    编号

    类型

    引入阶段

    排除阶段

    修复时间

    修复缺陷

     3/19

    1

    四则运算3

    编码

    编译

     30min

                 
  • 相关阅读:
    202104-2 邻域均值
    202104-1 灰度直方图
    1384. 饲料调配
    1381. 阶乘
    264. 丑数 II
    1380. 邮票
    42 新安装的idea必备设置
    41 cmd中解除被占用的端口
    40 文件在线预览
    39 进度条使用
  • 原文地址:https://www.cnblogs.com/liulitianxia/p/6582590.html
Copyright © 2011-2022 走看看