zoukankan      html  css  js  c++  java
  • 532124小组 20165321 四则运算

    要求

    第一周 输出阶段总结博客

    • 需求分析
    • 设计思路
    • 整数/多运算符(题目生成/题目运算判题)
    • JUnit测试
    • 扩展需求

    第二周 输出整体总结博客

    • 设计思路
    • 真分数(题目生成/题目运算判题)
    • JUnit测试
    • 扩展需求
        由于这次的实验题目比较难,且第一周时学习任务比较繁重,因此实验的第一周我们小组对于实验要求如何实现没有太多的头绪,一开始的进展较为缓慢。第一周,我们在算法思想上面稍稍借鉴了一下网上的一些博文,然后,再把各个算法整理出一个大概的框架,按照程序内容的构造结合起来,初步实现了实验第一周的要求。
        第二周,学习的担子没有那么重,我们有更多的时间来思考真分数四则运算与扩展需求的实现方法。经过了一周的思考,大体上算是完成第二周所要实现的内容。

    截图





    代码

    import java.util.*;
    public class SiZeYunSuan {
        public static void main(String[] args) {
            System.out.println("输入测试题数目:");
            Scanner sc=new Scanner(System.in);
            int number=sc.nextInt();
            double right = 0;
            double wrong = 0;
            for (int i = 0; i < number; i++) {
                System.out.println("第"+(i+1)+"道题,请在下方输入答案:");
                double op1=(int)(Math.random()*10);
                double op2=(int)(Math.random()*10);
                Random r3 = new Random();
                int m = r3.nextInt(4);
                char[] chs = {'+','-','*','/'};
                String Operator = String.valueOf(chs[m]);
                //生成题目
                if(Operator.equals("+")){
                    System.out.println(op1+"+"+op2+"=");
                    boolean b = add(op1,op2);
                    if(b == true){
                        right++;System.out.println("right! ");
                    }
                    else{
                        wrong++;System.out.println("no ");
                        System.out.println("right answer: "+(op1+op2));
                    }
                }
                else if(Operator.equals("-")){
                    System.out.println(op1+"-"+op2+"=");
                    boolean b =minus(op1,op2);
                    if(b == true){
                        right++;System.out.println("right! ");
                    }
                    else{
                        wrong++;System.out.println("no ");
                        System.out.println("right answer: "+(op1-op2));
                    }
                }
                else if(Operator.equals("*")){
                    System.out.println(op1+"×"+op2+"=");
                    boolean b =times(op1,op2);
                    if(b == true){
                        right++;System.out.println("right! ");
                    }
                    else{
                        wrong++;System.out.println("no ");
                        System.out.println("right answer: "+(op1*op2));
                    }
                }
                else{
                    System.out.println(op1+"÷"+op2+"=");
                    boolean b =Div(op1,op2);
                    if(b == true){
                        right++;System.out.println("right! ");
                    }else{
                        wrong++;System.out.println("no ");
                        System.out.println("right answer: "+op1/op2);
                    }
                }
            }
            System.out.println("做对了"+right+"道题.");
            System.out.println("做错了"+wrong+"道题.");
            System.out.println("正确率为"+(right/(wrong+right))*100+"%");
        }
        private static boolean add(double x,double y) {
            Scanner sc = new Scanner(System.in);
            double num1 = sc.nextDouble();
            double result = x + y;
            if(num1 == result){
                return true;
            }else{
                return false;
            }
        }
        private static boolean minus(double x,double y) {
            Scanner sc = new Scanner(System.in);
            double num1 = sc.nextDouble();
            double result = x - y;
            if(num1 == result){
                return true;
            }else{
                return false;
            }
        }
        private static boolean times (double x,double y) {
            Scanner sc = new Scanner(System.in);
            double num1 = sc.nextDouble();
            double result = x * y;
            if(num1 == result){
                return true;
            }else{
                return false;
            }
        }
        private static boolean Div(double x,double y) {
            Scanner sc = new Scanner(System.in);
            double num1 = sc.nextDouble();
            double result =x/y;
            if(num1 == result){
                return true;
            }else{
                return false;
            }
        }
    }
    
  • 相关阅读:
    小学二年级四则运算软件需求规格说明书
    周活动总结
    构建之法阅读笔记01
    学习进度条01
    四则运算
    软件工程概论
    课后作业1
    继承与多态-课后作业
    python文件处理-将图像根据坐标画矩形标记
    python文件处理-将图像根据坐标切割成若干小图
  • 原文地址:https://www.cnblogs.com/xpl20165321/p/8909415.html
Copyright © 2011-2022 走看看