标签:length int demo stat void puts ble while cto
设计佣金问题的程序
commission方法是用来计算销售佣金的需求,手机配件的销售商,手机配件有耳机(headphone)、手机壳(Mobile phone shell)、手机贴膜(Cellphone screen protector)三个部件,每个部件单价为:耳机80元,手机壳10元,手机贴膜8元,每月月末向制造商报告销量,制造商根据销量给销售商佣金。如果销售额不足1000元按10%提取佣金,1000-1800元部分按15%提取佣金,超过1800元部分按20%提取佣金。
程序要求:
1)先显示“请分别输入三种手机配件的销售情况:”
2)不满足条件,返回:“输入数量不满足要求”,返回重新输入;
3)条件均满足, 则返回佣金额。返回等待输入。
package demo; 2 3 import java.io.BufferedReader; 4 import java.io.InputStreamReader; 5 6 public class Commission { 7 public static final int Pheadphone = 80; 8 public static final int Pshell = 10; 9 public static final int Pprotector = 8; 10 11 private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 12 13 private static int headphone = -1; 14 private static int shell = -1; 15 private static int protector = -1; 16 17 public static double commission(int headphone,int shell,int protector){ 18 double sum = 0; 19 double salary = 0.0; 20 sum = Pheadphone*headphone + Pshell*shell +Pprotector*protector; 21 if(sum<1000) 22 salary = 0.1*Pheadphone*headphone + 0.1*Pshell*shell +0.1*Pprotector*protector; 23 else if(sum<1800) 24 salary = 0.15*Pheadphone*headphone + 0.15*Pshell*shell +0.15*Pprotector*protector; 25 else 26 salary = 0.2*Pheadphone*headphone + 0.2*Pshell*shell +0.2*Pprotector*protector; 27 return salary; 28 } 29 private static int[] input(){ 30 int a[] = null, i = 0; 31 try { 32 String str = bufferedReader.readLine(); 33 String s[] = str.split("\\s+"); 34 a = new int[s.length]; 35 for(String tmp : s){ 36 a[i++] = Integer.parseInt(tmp); 37 } 38 } catch (Exception e) { 39 a = null; 40 } 41 return a; 42 } 43 public static void main(String[] args) { 44 45 double salary = 0.0; 46 int exit = 1, a[] = null; 47 while(exit == 1){ 48 System.out.println("请分别输入三种手机配件的销售情况:"); 49 while(a == null){ 50 a = input(); 51 if(a == null || a.length != 3){ 52 System.out.println("输入数量不满足要求”,返回重新输入: "); 53 }else{ 54 headphone = a[0]; 55 shell = a[1]; 56 protector = a[2]; 57 } 58 } 59 if(headphone<0||shell<0||protector<0){ 60 System.out.println("输入数量不满足要求"); 61 continue; 62 } 63 salary = commission(headphone,shell,protector); 64 System.out.println("佣金额为:"+salary); 65 headphone = shell = protector = -1; 66 a = null; 67 } 68 } 69 70 }
标签:length int demo stat void puts ble while cto
原文地址:http://www.cnblogs.com/yuyaoc/p/6533130.html