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) { Candy bestChoko = new Chocolate("Ritter Sport with coconut", 100, 3.44, 30, "Ritter Sport", 36, Enums.ChocolateKinds.Milk); Candy zefir = new Marshmallow("Domashniy", 230, 2.77, 50, "AirSweet", Enums.MarshmallowKinds.Pink); Gift gift = new Gift("Christmas Gift", new List <Candy>()); gift.Add(bestChoko); gift.Add(zefir); Console.WriteLine("Gift weight: " + gift.Weight + "g\r\n"); var filtered = CandyFilters.WeightFilter(gift.Candies, 100, 300); filtered = CandyFilters.PriceFilter(filtered, 3, 4); Console.WriteLine("Filtered values:\r\n"); foreach (var item in filtered) { Console.WriteLine(item + "\r\n"); } gift.Candies.Sort(new PriceComparer <Candy>()); Console.WriteLine("Sorted values:\r\n"); foreach (var item in gift.Candies) { Console.WriteLine(item + "\r\n"); } DataManager manage = new DataManager(); manage.SaveJson(ref gift, "newgift.json"); Console.Read(); }
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"); }