示例#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);
        }
示例#2
0
        /// <summary>
        /// 跟用户交互的过程
        /// </summary>
        public void AskBuying()
        {
            Console.WriteLine("欢迎光临,请问您需要些什么?");
            Console.WriteLine("我们有Acer、SamSung、JiangYou、Banana");
            string strType = Console.ReadLine();

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

            //去仓库取货物
            ProductFather[] pros = ck.QuPros(strType, count);
            //下面该计算价钱了
            double realMoney = GetMoney(pros);

            Console.WriteLine("您总共应付{0}元", realMoney);
            Console.WriteLine("请选择您的打折方式 1--不打折 2--打九折 3--打85折 4--买300送50 5--买500送100");
            string input = Console.ReadLine();
            //通过简单工厂的设计模式根据用户的输入获得一个打折对象
            CalFather cal        = GetCal(input);
            double    totalMoney = cal.GetTotalMoney(realMoney);

            Console.WriteLine("打完折后,您应付{0}元", totalMoney);
            Console.WriteLine("以下是您的购物信息");
            foreach (var item in pros)
            {
                Console.WriteLine("货物名称:" + item.Name + "," + "\t" + "货物单价:" + item.Price + "," + "\t" + "货物编号:" + item.ID);
            }
        }
示例#3
0
        //和用户交互
        public void AskBuying()
        {
            Console.WriteLine("欢迎光临,请问您需要购买什么");
            Console.WriteLine("我们有 Acer,SamSung,Sauce,Banana");
            string strTaple = Console.ReadLine();

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

            //取货,里面包含需要取的货物名称和数量
            ProductFather[] pf = wh.Getproduct(strTaple, count);
            //结账
            double ReMoney = Money(pf);

            Console.WriteLine($"您总共需要支付{ReMoney}元");
            Console.WriteLine("请选择你的打折方式:1--不打折,2--打9折,3--打8.5折,4--满300减50,5--满500减100");
            string input = Console.ReadLine();
            //通过用户的输入返回一个打折的对象
            CalFather c          = Cf(input);
            double    totalmoner = c.GetTotlaMoney(ReMoney);

            Console.WriteLine($"打完折之后您应付{totalmoner}元");
            //Change(totalmoner);
            for (int i = 0; i < pf.Length; i++)
            {
                Console.WriteLine("您的购买信息为:");
                Console.WriteLine("商品名称:" + pf[i].Name + ",\t单价:" + pf[i].Price + ",\tID:" + pf[i].Id);
            }
        }
示例#4
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);
        }