UT源码_021
設計傭金
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)
?
// ETestOne by:mtLin 2017.3.10 import java.util.Scanner;public class One {/** hp:耳機 80元 mpc:手機殼 10元 cpsp:手機貼膜 8元*/public static void main(String[] args) {String line;int hp = 0, mpc = 0, cpsp = 0;String[] input = null;float money = 0;@SuppressWarnings("resource")Scanner scanner = new Scanner(System.in);while (true) {System.out.println("請分別輸入三種手機配件的銷售情況:");line = scanner.nextLine();input = line.split(" ");if (Judge(input)) {// 判斷是否不小于0if ((hp = Integer.parseInt(input[0])) < 0) {System.out.println("輸入數量不滿足要求");continue;}if ((mpc = Integer.parseInt(input[1])) < 0) {System.out.println("輸入數量不滿足要求");continue;}if ((cpsp = Integer.parseInt(input[2])) < 0) {System.out.println("輸入數量不滿足要求");continue;}} else {System.out.println("輸入數量不滿足要求");continue;}money = commission(hp, mpc, cpsp);System.out.println("傭金金額:" + money);}}// 計算傭金private static float commission(int hp, int mpc, int cpsp) {float commission = 0;int total = hp * 80 + mpc * 10 + cpsp * 8;if (total < 1000) {commission = (float) (total * 0.1);} else if (total <= 1800) {commission = (float) (1000 * 0.1 + (total - 1000) * 0.15);} else {commission = (float) (1000 * 0.1 + 800 * 0.15 + (total - 1800) * 0.2);}return commission;}// 判斷用戶輸入的是不是三個整數private static boolean Judge(String[] input) {String number = "0123456789";// 判斷輸入的是不是三個字符串if (input.length != 3) {return false;}// 判斷三個字符串是不是純數字且不含小數點for (int i = 0; i < 3; i++) {for (int j = 0; j < input[i].length(); j++) {if ("+-".indexOf(input[i].charAt(0)) == 1) {continue;}if (number.indexOf(input[i].charAt(j)) == -1) {return false;}}}return true;} }?
轉載于:https://www.cnblogs.com/mtLin/p/6531231.html
總結
- 上一篇: sublime 安装 插件
- 下一篇: JS window对象 返回前一个浏览的