码迷,mamicode.com
首页 > 其他好文 > 详细

第二次作业+105032014099

时间:2017-03-26 19:23:30      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:htm   scan   shel   匹配   price   情况   需求   学习心得   字符   

1.测试人员的测试帖连接:http://www.cnblogs.com/WuYeqian/p/6610568.html

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

(1)因为没有对输入内容进行是否是整数的判断,比如输入字符串就会程序崩溃,建议增加输入判断。

(2)代码不规范,出现if···else不匹配,total达到多大时如何处理。

       else if(total>=1800) //销售额大于1800提起20%佣金 
       commission=total*0.2;
       return commission;

(3)当执行用例1时,输出:“输入的数量不满足要求!”再输入三个值没有提示语句,最好能弄个循环判断输入。

(4)在double Commission(int headphone,int shell,int protector)方法中返回的是double型,但是int           total=headphone*headphone_price+shell*shell_price+protector*protector_price中total是int型的,这之间的转换出问题,需要修改。

(5)对输入的值最好有个最大范围限制处理,不然输入超出int能接受的值就程序崩溃了。

3.修正后的代码清单

 

import java.text.DecimalFormat;
import java.util.Scanner;
public class TestPractice {
    public static void main(String[] args) {
        
        Scanner input = new Scanner(System.in); //输入
        while(true)
        {
            System.out.println("请分别输入三种手机配件的销售情况:");
            int headphone_num;
            int shell_num;
            int protector_num;
            try {
                //输入耳机、手机壳、手机贴膜的数量
                System.out.print("请输入耳机的销售数量:");
                headphone_num=Integer.parseInt(input.next());
                System.out.print("请输入手机壳的销售数量:");
                shell_num=Integer.parseInt(input.next());
                System.out.print("请输入手机贴膜的销售数量:");
                protector_num=Integer.parseInt(input.next());
                if(headphone_num>0&&shell_num>0&&protector_num>0)
                {
                    TestPractice testPractice = new TestPractice();
                    //调用Commission方法
                    double commissiom = testPractice.Commission(headphone_num, shell_num, protector_num);
                    DecimalFormat df=new DecimalFormat("#.0");           //限制输出佣金的小数点后的位数
                    System.out.println("佣金:"+df.format(commissiom));    //输出佣金
                }
                else{
                    System.out.println("输入的数量不满足要求!请重新输入!");
                }
                continue;
            } catch (Exception e) {
                System.out.println("出现异常:"+e);        
            }
        }
    }
        
//计算佣金
double Commission(int headphone,int shell,int protector)
{   
    double commission=0;     //初始化佣金为0
    int headphone_price=80;  //耳机单价80;
    int shell_price=10;      //手机壳单价10;
    int protector_price=8;   //手机贴膜单价8;
    int total=headphone*headphone_price+shell*shell_price+protector*protector_price;
    if(total<1000&&total>0){            //销售额不足1000提取10%佣金
        commission=total*0.1;
    }else if(total<=1800){     //销售额在1000-1800,提取15%佣金
        commission=total*0.15;
    }else {                    //销售额大于1800提起20%佣金   
    commission=total*0.2;
    }
    return commission;
}
}

4.修正后心得体会:

(1)代码变更:主要对程序的输入内容是否为整数进行修改,循环优化以及对一些小细节的处理。

(2)缺陷的原因:对程序的需求考虑不周,容易忽略隐藏的条件。

(3)学习心得:多动手。                    

第二次作业+105032014099

标签:htm   scan   shel   匹配   price   情况   需求   学习心得   字符   

原文地址:http://www.cnblogs.com/ddanwu-blogs/p/6623048.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!