UT源码105032014099

设计佣金问题的程序

commission方法是用来计算销售佣金的需求,手机配件的销售商,手机配件有耳机(headphone)、手机壳(Mobile phone shell)、手机贴膜(Cellphone screen protector)三个部件,每个部件单价为:耳机80元,手机壳10元,手机贴膜8元,每月月末向制造商报告销量,制造商根据销量给销售商佣金。如果销售额不足1000元按10%提取佣金,1000-1800元部分按15%提取佣金,超过1800元部分按20%提取佣金。

 程序要求:

1)先显示“请分别输入三种手机配件的销售情况:”

2)不满足条件,返回:“输入数量不满足要求”,返回重新输入;

3)条件均满足, 则返回佣金额。返回等待输入。


import java.util.Scanner;

public class TestPractise {
public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner input = new Scanner(System.in); //输入
System.out.println("请分别输入三种手机配件的销售情况:");
//输入耳机、手机壳、手机贴膜的数量
int headphone_num;
int shell_num;
int protector_num;
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)
{
System.out.println("输入的数量不满足要求!");
//返回重新输入
headphone_num=Integer.parseInt(input.next());
shell_num=Integer.parseInt(input.next());
protector_num=Integer.parseInt(input.next());
}
TestPractise testPractise = new TestPractise();
//调用Commission方法
double commissiom = testPractise.Commission(headphone_num, shell_num, protector_num);
System.out.println("佣金:"+commissiom); //输出佣金
}

//计算佣金
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>=1000 && total<1800) //销售额在1000-1800,提取15%佣金
commission=total*0.15;
else if(total>=1800) //销售额大于1800提起20%佣金
commission=total*0.2;
return commission;
}
}

 

posted @ 2017-03-10 18:04  Esperer`  阅读(291)  评论(0编辑  收藏  举报