第二次作业+105032014123

 

1.测试帖链接:http://www.cnblogs.com/ChainYugi/p/6601316.html

2.测试人员提出的问题、发现的缺陷

(1)题意理解错误。题意要求为如果销售额不足1000元按10%提取佣金,1000-1800元部分按15%提取佣金,超过1800元部分按20%提取佣金。而该程序则无视了“部分”,将1000-1800元的销售额全额按15%提取佣金,超过1800元的销售额全额按20%提取佣金,导致错误。

(2)对负数输入的判断仅一次判断。从测试用例1和2可以看出,程序对负数输入的判断仅有1次,无论第二次输入的数是否是正数一律通过并赋值给相应变量,导致测试用例1的错误。

(3)没有对非整数输入进行判断。用例9、10和11可以明显看出程序不支持小数、字符等的输入,并且会使程序崩溃。

(4)逻辑错误

3.修正后的代码清单

package Test1;
import java.io.IOException;
import java.util.Scanner;

public class yongjin01 {
    public static void main(String[] args){
        yongjin01 yj = new yongjin01();
        
        System.out.println("请分别输入三种手机配件的销售情况:");
        
            double headphone = yj.Input(0);
        
            double shell = yj.Input(0);
            double protector = yj.Input(0);
            System.out.println("耳机数量:"+headphone+"\n手机壳数量:"+shell+" \n手机贴膜数量:"+protector);
            double commission = yj.Commission(headphone, shell, protector);
            System.out.println("销售佣金:"+commission);
        
        }
    public double Input(double number){
        double num = 0;
        Scanner scanner = new Scanner(System.in);
     try{
        if(num<0){
            System.out.println("输入的数量不满足要求!");
            
        }else{
            num = scanner.nextDouble();
            return num;
        }
     }catch(Exception e){System.out.println("输入不合法!");}
        return num;
                
    }
    public double Commission(double headphone,double shell,double protector){
        double commission = 0;   //定义佣金;
        double headphonePrice = 80;
        double shellPrice = 10;
        double protectorPrice = 8;
        double headphonesales = headphonePrice*headphone;
        double shellsales = shellPrice*shell;
        double protectorsales = protectorPrice*protector;
        double sales  = headphonesales+shellsales+protectorsales;
        if(sales>1800){
            commission = 0.10*1000;
            commission = commission+0.15*800;
            commission = commission+0.20*(sales-1800);
        }else if(sales>1000){
            commission = 0.10*1000;
            commission = commission+0.15*(sales-1000);
        }
        else 
            commission = 0.10*sales;
        
        return commission;
    }
}

4.修正后心得体会

  • 介绍自己代码做了怎样的变更
  • 分析出现缺陷的原因
  • 对这部分教材内容的学习心得

变更:修改了计算方法,并且使用try...catch来处理异常。

原因:之前没有理解好题意,导致错误,并且没有考虑到字符类型的输入会导致程序奔溃。

心得:语句覆盖和判定覆盖能对于程序代码的测试范围及深度有限。

posted @ 2017-03-27 19:22  高浩峰  阅读(260)  评论(0编辑  收藏  举报