static void Main(string[] args) { Creator[] creators = new Creator[3]; creators[0] = new CandyCreator(); creators[1] = new CookieCreator(); creators[2] = new MarshmallowCreator(); IGift gift = new Gift(); foreach (Creator i in creators) { if (i is CandyCreator) { gift.Add(i.FactoryMethod("Mars", 80, 105, 1, TypeCandy.ChocolateCandy)); gift.Add(i.FactoryMethod("ChupaChups", 25, 75, 2, TypeCandy.Lollipop)); } if (i is CookieCreator) { gift.Add(i.FactoryMethod("Chico-pia", 100, 115, 4, TypeCoockie.biscuit)); } if (i is MarshmallowCreator) { gift.Add(i.FactoryMethod("Marshmallow", 230, 76.6f, 1, TasteMarshmallow.Orange)); } } gift.Sort(); gift.ShowItems(); Console.WriteLine(); Console.WriteLine("вкусность конфетки"); Marshmallow marshmallowsweet = new Marshmallow("Marshmallow", 230, 76.6f, 1, TasteMarshmallow.Orange); marshmallowsweet.TypeSweet(); Console.WriteLine(); Console.WriteLine("сортировка по сахару"); foreach (var items in gift.FindCandyBySugar(70, 110)) { Console.WriteLine("{0}, Сахар: {1}", items.Name, items.Sugar); } Console.WriteLine(); Console.WriteLine("Вес подарка: {0}", gift.GiftWeight()); Console.ReadKey(); }
static void Main(string[] args) { IGift gift = new Gift(); Sweet candy1 = new Candy("Кремка", "Russia", 33, 180, TypeOfCandy.Lollipop); Sweet candy2 = new Candy("Toffifee", "Germany", 41, 125, TypeOfCandy.ChocalateCandy); Sweet candy3 = new Chocalate("Nestle", "Switzerland", 15, 85, ColorOfChocalate.WhiteChocolate); Sweet candy4 = new Chocalate("Milka", "Switzerland", 13, 100, ColorOfChocalate.BlackChocolate); Sweet candy5 = new Biscuit("Thick&Crunchy Oatcakes", "The United Kingdom", 14, 300, TypeOfBiscuit.OatCookies); Sweet candy6 = new Biscuit("Leibniz Petit Beurre", "Poland", 22, 220, TypeOfBiscuit.Shortbread); gift.Add(candy1); gift.Add(candy2); gift.Add(candy3); gift.Add(candy4); gift.Add(candy5); gift.Add(candy6); gift.GiftPrint(); gift.SortByWeight(); Console.WriteLine("After sorting : \n"); gift.GiftPrint(); int left_border, right_border; do { Console.WriteLine("Enter borders of sugar content :"); Console.Write("Left border : "); left_border = int.Parse(Console.ReadLine()); Console.Write("Right border : "); right_border = int.Parse(Console.ReadLine()); if (left_border < 0 || right_border < 0 || left_border > right_border) { Console.Clear(); Console.WriteLine("Wrong Input!"); } } while (left_border < 0 || right_border < 0 || left_border > right_border); Console.WriteLine($"\nSweets corresponding to the [{left_border}g ; {right_border}g] range of sugar content:"); foreach (var item in gift.FindCandyBySugar(left_border, right_border)) { Console.WriteLine($" Sweet name: { item.Name}, Sugar: {item.Sugar}g"); } Console.WriteLine($"\nGift weight: {gift.GiftWeight()}g"); }