Exemple #1
0
        //public void Change(double totalmoner)
        //{
        //    while (true)
        //    {
        //        Console.WriteLine("请输入付款金额:");
        //        double Payment = double.Parse(Console.ReadLine());
        //        if (Payment - totalmoner >= 0)
        //        {
        //            Console.WriteLine($"找您{Payment - totalmoner}");
        //            break;
        //        }
        //        else
        //        {
        //            Console.WriteLine("您输入的金额不足!");
        //            Console.WriteLine("请继续付款");
        //            Payment = double.Parse(Console.ReadLine());
        //        }
        //    }
        //}

        /// <summary>
        /// 根据用户的输入,选择打折的方式
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public CalFather Cf(string input)
        {
            CalFather c = null;

            switch (input)
            {
            case "1":
                c = new CalNone();
                break;

            case "2":
                c = new CalRate(0.9);
                break;

            case "3":
                c = new CalRate(8.5);
                break;

            case "4":
                c = new CalMN(300, 50);
                break;

            case "5":
                c = new CalMN(500, 100);
                break;
            }
            return(c);
        }
Exemple #2
0
        /// <summary>
        /// 根据用户选择的打折方式返回一个打折对象
        /// </summary>
        /// <param name="input">用户的选择</param>
        /// <returns>返回的父类对象,但是里面装的是子类对象</returns>
        public CalFather GetCal(string input)
        {
            CalFather cal = null;

            switch (input)
            {
            case "1": cal = new CalNormal();
                break;

            case "2": cal = new CalRate(0.9);
                break;

            case "3": cal = new CalRate(0.85);
                break;

            case "4": cal = new CalMN(300, 50);
                break;

            case "5": cal = new CalMN(500, 100);
                break;
            }
            return(cal);
        }