if这里不复杂阿,如果不用if 那用case ,这里条件不多,还是if可以

解决方案 »

  1.   

    代码逻辑不清晰:
    1. 部分打折和返现的业务逻辑写到了现金收取工厂中
    2. 打折、返现、VIP之间关系混乱,首先你要明确这三者之间的关系。CashContext功只需要协调打折、返现、VIP三者之间的关系,例如多少钱的返现多少、多少数量的打几折这种逻辑是在打折和返现类中进行判断的。
      

  2.   

    建议按以下结构设计代码:class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请依次按提示输入:");
                Console.WriteLine("输入购买金额:");
                var inputMoney = double.Parse(Console.ReadLine());
                Console.WriteLine("输入购买数量:");
                var inputNumbers = int.Parse(Console.ReadLine());
                Console.WriteLine("@输入是否是会员:    0:非会员;    1:银卡会员;    2:金卡会员;");
                var inputVip = int.Parse(Console.ReadLine());
                var Person1 = new CashContext(inputMoney, inputNumbers,inputVip);
     
                Console.ReadLine();
            }
        }
        
        //现金收取父类
        internal abstract class CashReap
        {
            public abstract double AcceptCash(double money);
        }
        
        //打折子类
        internal class CashDiscount : CashReap
        { 
            ......
            public int ProductNumbers { get; set; }      // 此处需要增加根据数量自动换算折扣率的代码
            ......
        }
        
        //返现子类
        internal class CashRebate : CashReap
        {
     
            ......
            public float TotalPrices { get; set; }      // 此处需要增加根据总金额自动换算返还金额的算法 
            ......
        }
        //VIP类
        internal class VipDiscount : CashReap
        {
          ......
        }
     
        //现金收取工厂
        internal class CashContext
        {
            private CashReap _cReap;
     
            public CashContext(double totalMoney,int productnumbers,int isVip)
            {
                // 活支折扣
                CashDiscount cs1 = new CashDiscount();
                cs1.productnumbers == 1;  
                totalMoney = cs1.AcceptCash(totalMoney);
                
                // VIP折扣
                VipDiscount cs2 = new VipDiscount(isVip);
                totalMoney = cs2.AcceptCash(totalMoney);           
                
                // 返现
                CashRebater cs3 = new CashRebate();
                totalMoney = cs3.AcceptCash(totalMoney)
     
                Console.WriteLine("应付总额为: "+ totalMoney.tostring() +" 元");
            }
     
        }