第二次作业+105032014033
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第二次作业+105032014033相关的知识,希望对你有一定的参考价值。
1.测试代码连接:http://www.cnblogs.com/5257yu/p/6601603.html
2.提出的建议:
1)该代码没有按照要求将结果作为字符串输出。
2)使用 if 时,应当确保判断条件内所有的范围都能涉及到, if 后面应当接else或者else if。
3.修改后代码:
import java.util.Scanner; public class Yongjin01 { 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; } }
public class ruance2 { public static void main(String[] args) { while(true){ 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); } } }
4.心得体会
根据测试者的建议增加了else if判定,解决了输入数较小是出现负数的问题,改进了程序的功能,能够符合题意,符合实际。
以上是关于第二次作业+105032014033的主要内容,如果未能解决你的问题,请参考以下文章