• 第二次作业+105032014138


     

    被测代码地址:http://www.cnblogs.com/lyz007/p/6530327.html

     

       

    2.提出的问题、发现的缺陷

      1)在测试字母数字混合输入的情况下不能很好的进行合法性判断。

      2)if与else嵌套语句太多,代码读起来较复杂。数量边界没有设定清楚

      3)代码建议必要的注释

     3.修改后的代码

    import java.util.Scanner;

     

    public class Caculator {

        public static float commission(int Headphone,int Shell,int Protector){

            int All = Headphone*80+Shell*10+Protector*8;

            float commission = 0;

            if(All<1000&&All>=0)

            {

                commission = (float) (All*0.1);

                System.out.println("本次销售所得佣金为:"+commission);

            }

            else if(All>=1000 && All<=1800)

            {

                commission = (float) (100+(All-1000)*0.15);

                System.out.println("本次销售所得佣金为:"+commission);

            }

            else if(All>1800)

            {

                commission = (float) (100+800*0.15+(All-1800)*0.2);

                System.out.println("本次销售所得佣金为:"+commission);

            }  

            return commission;

        }

        public static void main(String[] args){

            while(true)

            {

                int Headphone=0;

                int Shell=0;

                int Protector=0;

                Scanner scanner=new Scanner(System.in) ;

                try{

                        System.out.println("请输入耳机的销售情况:");

                         Headphone=scanner.nextInt();

                        System.out.println("请输入手机壳的销售情况:");

                         Shell=scanner.nextInt();

                        System.out.println("请输入手机膜的销售情况:");

                         Protector=scanner.nextInt();

                         scanner.close();

                }catch(Exception e){

                    System.out.println("出现异常:"+e);

                    System.exit(-1);

                }

                if(Headphone>=0&&Shell>=0&&Protector>=0)

                {

                    commission(Headphone,Shell,Protector);

                }

                else

                {

                    System.out.println("输入有误,请重新输入!");

                }    

                

            }

        }

    }

    学习心得

    1)我明白了在编写代码时思路是很重要的,要多加思考才能发现更加简洁的设计方案

    2)我发现很多错误都来源与粗心大意,明白了以后在编写代码时要仔细检查,例如在计算当销售金额大于1800时所得到的拥金,如果好好检查就能避免这样的错误

    3)通过对本章知识的学习,进一步了解了软件测试,同时通过对本章的学习也使我在编写代码时更加严谨了

     

  • 相关阅读:
    B. Connecting Universities DFS,无向树
    HDU 5808 Price List Strike Back bitset优化的背包。。水过去了
    uva 6910
    HDU 5778 abs 数学
    Invitation Cards POJ 1511 SPFA || dij + heap
    HDU 2243 考研路茫茫——单词情结 求长度小于等于L的通路总数的方法
    cmd链接mysql
    如何设置远程访问mysql
    ERROR 1045 (28000): Access denied for user'root'@'localhost'(using password:YES)51Testing软件测试网-H*?U)}$h }P6H4H
    String ,StringBuffer,StringBuilder的区别(转)
  • 原文地址:https://www.cnblogs.com/m350377814/p/7075491.html
Copyright © 2020-2023  润新知