zoukankan      html  css  js  c++  java
  • 作业三:代码复审

    我此次的代码复审是复审我们班李瑶的代码,她的代码比较简单,运行后需选择需要运行的算法(加减乘除)。

    1.概要部分

    她的代码符合小学生加减乘除算数需求,并且可以执行真分数的运行。

    2.代码部分

    她的代码采用了JAVA编程,是使用MyEclipse编写的,在将来移植过程中并可能会出现错误,需加以调适。

    代码中多次采用了switch语句

            switch(s){
            case 1:System.out.println("------|"+a+"+"+b+"=?|-----");result = a+b;res();break;
            case 2:System.out.println("------|"+a+"-"+b+"=?|-----");result = a-b;res();break;
            case 3:System.out.println("------|"+a+"*"+b+"=?|-----");result = a*b;res();break;
            case 4:System.out.println("------|"+a+"/"+b+"=?|-----");{float c=a;float d =b;result=c/d;};res();break;
            default:System.out.println("输入有误,请重新开始");main(null);break;
            }
            Scanner select = new Scanner(System.in);
            int se = select.nextInt();
            switch(se){
            case 1:System.out.println("本题的结果:"+result);main(null);break;
            case 2:main(null);break;
            default:System.out.println("输入有误,请重新开始");main(null);
            }
            
        }
    
        
    }
    

      

    3.缺乏可读性

    代码缺少相应的注释,应添加相应的注释,方便非专业人士解读。

    import java.util.Random;
    import java.util.Scanner;
    
    
    public class text {
        public static void res(){
            System.out.println("1、显示结果	2、直接开始下一题");
        }
        
        public static void main(String[] args) {
            System.out.println("*****************请选择要随机生成的算式*******************");
            System.out.println("	1、加法	2、减法	3、乘法	4、除法");
            System.out.println("***************************************************");
            Scanner sc = new Scanner(System.in);
            int s = sc.nextInt();
            double result=0;
            Random r = new Random();
            int a = r.nextInt(100);
            int b = r.nextInt(100);
            switch(s){
            case 1:System.out.println("------|"+a+"+"+b+"=?|-----");result = a+b;res();break;
            case 2:System.out.println("------|"+a+"-"+b+"=?|-----");result = a-b;res();break;
            case 3:System.out.println("------|"+a+"*"+b+"=?|-----");result = a*b;res();break;
            case 4:System.out.println("------|"+a+"/"+b+"=?|-----");{float c=a;float d =b;result=c/d;};res();break;
            default:System.out.println("输入有误,请重新开始");main(null);break;
            }
            Scanner select = new Scanner(System.in);
            int se = select.nextInt();
            switch(se){
            case 1:System.out.println("本题的结果:"+result);main(null);break;
            case 2:main(null);break;
            default:System.out.println("输入有误,请重新开始");main(null);
            }
            
        }
    
        
    }
  • 相关阅读:
    BlogEngine.Net架构与源代码分析系列part5:对象搜索——IPublishable与Search
    SqlCacheDependency
    Office SharePoint Server 2007
    Castle Active Record for .NET2.0快速入门示例
    PetShop的系统架构第三篇
    中文分词核心配置
    BlogEngine.Net架构与源代码分析系列part3:数据存储——基于Provider模式的实现
    Cocos2d开发系列(二)
    高负载、高并发网站架构知识汇总大流量网站架构的几点认识
    使用Application变量
  • 原文地址:https://www.cnblogs.com/shaomeifu/p/5287218.html
Copyright © 2011-2022 走看看