UT源码 087
Posted Lucerner
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UT源码 087相关的知识,希望对你有一定的参考价值。
设计佣金问题的程序
commission方法是用来计算销售佣金的需求,手机配件的销售商,手机配件有耳机(headphone)、手机壳(Mobile phone shell)、手机贴膜(Cellphone screen protector)三个部件,每个部件单价为:耳机80元,手机壳10元,手机贴膜8元,每月月末向制造商报告销量,制造商根据销量给销售商佣金。如果销售额不足1000元按10%提取佣金,1000-1800元部分按15%提取佣金,超过1800元部分按20%提取佣金。
程序要求:
1)先显示“请分别输入三种手机配件的销售情况:”
2)不满足条件,返回:“输入数量不满足要求”,返回重新输入;
3)条件均满足, 则返回佣金额。返回等待输入。
float commission (int headphone, int shell, int protector)
import java.util.Scanner; public class CommissionTest { public static final float HEADPHONE_PRICE = 80;// 耳机单价 public static final float PROTCTOR_PRICE = 8;// 手机贴膜单价 public static final float MOBILESHELL_PRICE = 10;// 手机壳单价 public static final float MIN_RATE = 0.1f;// 不足1000的佣金比率 public static final float MID_RATE = 0.15f;// 1000-1800的佣金比率 public static final float MAX_RATE = 0.2f;// 超过1800的佣金比率 public static void main(String args[]) { while (true) { Scanner input = new Scanner(System.in); System.out.println("请分别输入三种手机配件的销售情况"); System.out.println("耳机销售情况:"); int headPhoneNum = CheckNum(input.nextInt()); System.out.println("手机壳销售情况:"); int mobPhoneShellNum = CheckNum(input.nextInt()); System.out.println("手机贴膜销售情况:"); int cellSrcProNum = CheckNum(input.nextInt()); float commission = Commission(headPhoneNum, mobPhoneShellNum, cellSrcProNum); System.out.println("收取的佣金为" + commission); System.out.println("是否退出?输入-1退出,按任意数字继续"); if (Integer.parseInt(input.next()) == -1) { System.exit(1); } System.out.println("----------------------------------"); } } public static int CheckNum(int num) {// 检查每次输入是否满足条件 Scanner input = new Scanner(System.in); while (true) { if (num < 0) { System.out.println("输入数量不满足要求,请重新输入"); num = input.nextInt(); } else { return num; } } } // 计算佣金 public static float Commission(int headPhone, int mobPhoneshell, int protctor) { float commission = 0;// 佣金 float headPhoneSale = headPhone * HEADPHONE_PRICE; float mobPhoneShellSale = mobPhoneshell * MOBILESHELL_PRICE; float protctorSale = protctor * PROTCTOR_PRICE; float totalSale = headPhoneSale + mobPhoneShellSale + protctorSale; if (totalSale < 1000 && totalSale > 0) { commission = totalSale * MIN_RATE; } else if (totalSale <= 1800) { commission = totalSale * MID_RATE; } else { commission = totalSale * MAX_RATE; } return commission; } }
以上是关于UT源码 087的主要内容,如果未能解决你的问题,请参考以下文章