第二次作业+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)通过对本章知识的学习,进一步了解了软件测试,同时通过对本章的学习也使我在编写代码时更加严谨了

 

转载于:https://www.cnblogs.com/m350377814/p/7075491.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值