示例#1
0
 public object CopyRequest()
 {
     if (ChikenOrEgg is ChickenOrder)
     {
         ChickenOrder c = (ChickenOrder)ChikenOrEgg;
         return(c.Copy());
     }
     else if (ChikenOrEgg is EggOrder)
     {
         EggOrder e = (EggOrder)ChikenOrEgg;
         return(e.Copy());
     }
     throw new Exception("Hey Guy You haven't instance!");
 }
示例#2
0
        public string PrepareFood(object o)
        {
            if (o is ChickenOrder)
            {
                if (chickenPrepared)
                {
                    throw new Exception("already chicken kaput!");
                }
                chickenPrepared = true;

                ChickenOrder c = (ChickenOrder)o;
                for (int i = 0; i < c.GetQuantity(); i++)
                {
                    c.CutUp();
                }
                c.Cook();
                return("indicating preparation has been completed");
            }
            else if (o is EggOrder)
            {
                if (eggPrepared)
                {
                    throw new Exception("already eggs kaput!");
                }
                eggPrepared = true;
                var      rotten = 0;
                EggOrder e      = (EggOrder)o;
                for (int i = 0; i < e.GetQuantity(); i++)
                {
                    //TODO: You called e.DiscardShell() twice. Please call it only once.
                    try
                    {
                        e.Crack();
                    }
                    catch
                    {
                        rotten++;
                    }
                    e.DiscardShell();
                }
                e.Cook();
                return("indicating preparation has been completed " + rotten.ToString());
            }
            throw new Exception("Hey Guy You haven't instance!");
        }