//简单工厂,根据输入的参数,返回一个父类对象。父类对象中装的是子类对象。 //参数:优惠的选项 //返回值:打折类的父类 public CalFather CalMoney(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; default: break; } return(cal); }
public void AskBuying() { Console.WriteLine("请问您要买什么吗?"); Console.WriteLine("我们这里有Acer,Samsung,Banana,JiangYou"); string strType = Console.ReadLine(); Console.WriteLine("需要多少?"); int count = Convert.ToInt32(Console.ReadLine()); //去仓库取货 ProductFather[] pros = ck.QuHuo(strType, count); //计算货物的价钱 double realMoney = GetMoney(pros); Console.WriteLine("你实际应付{0}", realMoney); //打折信息 Console.WriteLine("优惠促销1、不打折;2、打九折;3、打八五折;4、买300送50;5、买500送100"); string input = Console.ReadLine(); CalFather cal = CalMoney(input); Console.WriteLine("实际应付{0}元", cal.GetPayMoney(realMoney)); //给出小票的信息 Console.WriteLine("以下是您的购物信息"); foreach (var item in pros) { Console.WriteLine("货物名称:{0},货物单价:{1},货物编号:{2}", item.Name, item.Price, item.ID); } }