Beispiel #1
0
        /// <summary>
        /// 根据用户的选择的打折方式返回一个打折方式
        /// </summary>
        /// <param name="input">用户的选择</param>
        /// <returns>打折对象</returns>
        public DiscountFather GetDiscount(string input)
        {
            DiscountFather dis = null;

            switch (input)
            {
            case "1":
                dis = new DiscountNormal();
                break;

            case "2":
                dis = new DiscountRate(0.9);
                break;

            case "3":
                dis = new DiscountRate(0.85);
                break;

            case "4":
                dis = new DiscountGift(50, 300);
                break;

            case "5":
                dis = new DiscountGift(100, 500);
                break;

            default:

                break;
            }
            return(dis);
        }
Beispiel #2
0
        /// <summary>
        /// 跟用户交互的过程
        /// </summary>
        public void Askbuying()
        {
            Console.WriteLine("欢迎光临,请问您需要些什么?");
            Console.WriteLine("我们有弘基笔记本、三星手机、酱油和香蕉");
            string strType = Console.ReadLine();

            Console.WriteLine("您需要多少?");
            int count = Convert.ToInt32(Console.ReadLine());

            // 去仓库取货物
            ProductFather[] pros = sh.Shipment(strType, count);
            // 计算价格
            double cust = GetMoney(pros);

            Console.WriteLine("您好,一共{0}元钱", cust);
            Console.WriteLine("请选择您的打折方式 1--不打折  2--打九折  3--打85折  4--买300送50  5--买500送100");
            string         input      = Console.ReadLine();
            DiscountFather dis        = GetDiscount(input);
            double         totalMoney = dis.GetTotalMoney(cust);

            Console.WriteLine("打折后,您应付{0}元", totalMoney);
            PrintSumary(pros);
        }