public void Remove(Sweet sweet) { if (!Sweets.Remove(sweet)) { throw new ArgumentOutOfRangeException(); } Weight -= sweet.Weight; }
public void RemoveAt(int index) { if (index < 0 || index > Sweets.Count) { throw new ArgumentOutOfRangeException(); } Weight -= Sweets[index].Weight; Sweets.RemoveAt(index); }
public IEnumerable <ISweet> SearchBySugarContent(double lower, double upper) { var sweetsBySugarContent = Sweets .Where(x => x is ISweet) .Where(x => x.SugarContent >= lower) .Where(x => x.SugarContent <= upper) .ToArray(); return(sweetsBySugarContent); }
//Продукт, Кондитерское изделие, Товар, Цветы, Торт, Часы, Конфеты; static void Main(string[] args) { // Задание 1 Console.WriteLine($"Задание №1"); Sweets s1 = new Sweets("Алёнка"); Sweets s0 = new Sweets("Пчёлка"); Console.WriteLine(s1.Equals(s0)); Console.WriteLine(s1.GetType()); s1.ToString(); Console.WriteLine(s1.GetHashCode()); // Задание 2, 3, 4 Console.WriteLine($"Задание №2,3,4"); s1.GetInfo(); // Задание 2 virtual -> override Run m1 = new Run(); // интерфейс m1.GetInfo(); // вызванный из объекта Run ((IMovable)m1).GetInfo(); // вызванный из интерфейса IMovable // Задание 5 Console.WriteLine($"Задание №5"); Goods a = new Goods(); Sweets s = new Sweets(); Goods c = new Sweets(); if (a is Goods) { Console.WriteLine("Переменная a имеет тип Goods"); } if (s is Sweets) { Console.WriteLine("Тип переменной s унаследован от класса Goods"); } if (c is Goods) { Console.WriteLine("Переменная c имеет тип Goods"); } else { Console.WriteLine("Переменная c имеет тип Sweets"); } // Задание 6, 7 Console.WriteLine($"Задание №6,7"); Clock s2 = new Clock("Rolex"); Cake s3 = new Cake("Графские развалины"); object[] testArray = new object[] { s1, s2, s3 }; Printer p1 = new Printer(); for (int i = 0; i < testArray.Length; i++) { p1.IAmPrinting(testArray[i]); } }
private Product AddNewProduct(string[] splittedValues) //return kann parent PRODUCT sein und alle Kinder auch zurückgeben!!!!! { Product newProd; //initialisieren ohne zuweisung GEHT!!! string type = splittedValues[4].ToLower(); if (type == "alcohol") { newProd = new Alcohol(); } else if (type == "fruits") { newProd = new Fruits(); } else if (type == "sweets") { newProd = new Sweets(); } else { newProd = new Vegetables(); } newProd.ID = splittedValues[0]; newProd.Cost = double.Parse(splittedValues[1].Replace("€", "")); newProd.Name = splittedValues[2]; newProd.Usebefore = splittedValues[3]; newProd.Type = type; if (splittedValues[5] == "normal") { newProd.Storagetype = Storagetype.NORMAL; } else if (splittedValues[5] == "fridge") { newProd.Storagetype = Storagetype.FRIDGE; } else if (splittedValues[5] == "freezer") { newProd.Storagetype = Storagetype.FREEZER; } return(newProd); }
public IEnumerable <ISweet> SortBySugarContent() { var sortBySugarContent = Sweets.OrderBy(x => x.SugarContent).ToArray(); return(sortBySugarContent); }
public IEnumerable <ISweet> SortByName() { var sortByName = Sweets.OrderBy(x => x.Name).ToArray(); return(sortByName); }
public IEnumerable <ISweet> SortByWeight() { var sortByWeight = Sweets.OrderBy(x => x.Weight).ToArray(); return(sortByWeight); }
public void addSweet(Sweet a) { Sweets.AddLast(a); }
public void SweetAdd(ISweet item) { Sweets.Add(item); }
public Chocolate FindFirstChocolateCandy() { return((Chocolate)Sweets.Find(x => x is Chocolate)); }
public Sugar FindFirstSugarCandy() { return((Sugar)Sweets.Find(x => x is Sugar)); }
public Sweet FindFirstBySugarPercentageRange(double minimumPercentage, double maximumPercentage) { return(Sweets.Find(x => x.SugarPercentage >= minimumPercentage && x.SugarPercentage <= maximumPercentage)); }
public void Sort(Comparison <Sweet> comparer) { Sweets.Sort(comparer); }
public void BuildSweets(Sweets sw) => meal.Sweets = sw;
public void SweetClear() { Sweets.Clear(); }
public double Visit(Sweets sweets) => Math.Round(sweets.Price * promotion, 2);
public bool SweetContains(ISweet item) { return(Sweets.Contains(item)); }
public void removeSweet(Sweet a) { Sweets.Remove(a); }
public bool SweetRemove(ISweet item) { return(Sweets.Remove(item)); }
public double CalculateDiet() { int total_items = 7; double fruit_score = 0, veg_score = 0, fish_score = 0, wg_score = 0, fastfood_score = 0, sweets_score = 0, beverage_score = 0; #region Fruit if (Fruits == null) { total_items--; } else if (Fruits != null && Fruits.Trim().Equals("Often")) { fruit_score = 10; } else if (Fruits != null && Fruits.Trim().Equals("Sometimes")) { fruit_score = 5; } else if (Fruits != null && Fruits.Trim().Equals("Rarely")) { fruit_score = 0; } #endregion #region Vegetables if (Vegetables == null) { total_items--; } else if (Vegetables != null && Vegetables.Trim().Equals("Often")) { veg_score = 10; } else if (Vegetables != null && Vegetables.Trim().Equals("Sometimes")) { veg_score = 5; } else if (Vegetables != null && Vegetables.Trim().Equals("Rarely")) { veg_score = 0; } #endregion #region Fish if (Fish == null) { total_items--; } else if (Fish != null && Fish.Trim().Equals("Often")) { fish_score = 10; } else if (Fish != null && Fish.Trim().Equals("Sometimes")) { fish_score = 5; } else if (Fish != null && Fish.Trim().Equals("Rarely")) { fish_score = 0; } #endregion #region Wholegrain if (Wholegrain == null) { total_items--; } else if (Wholegrain != null && Wholegrain.Trim().Equals("Often")) { wg_score = 10; } else if (Wholegrain != null && Wholegrain.Trim().Equals("Sometimes")) { wg_score = 5; } else if (Wholegrain != null && Wholegrain.Trim().Equals("Rarely")) { wg_score = 0; } #endregion #region Fastfood if (Fastfood == null) { total_items--; } else if (Fastfood != null && Fastfood.Trim().Equals("Often")) { fastfood_score = 0; } else if (Fastfood != null && Fastfood.Trim().Equals("Sometimes")) { fastfood_score = 5; } else if (Fastfood != null && Fastfood.Trim().Equals("Rarely")) { fastfood_score = 10; } #endregion #region Sweets if (Sweets == null) { total_items--; } else if (Sweets != null && Sweets.Trim().Equals("Often")) { sweets_score = 0; } else if (Sweets != null && Sweets.Trim().Equals("Sometimes")) { sweets_score = 5; } else if (Sweets != null && Sweets.Trim().Equals("Rarely")) { sweets_score = 10; } #endregion #region Beverages if (Beverages == null) { total_items--; } else if (Beverages != null && Beverages.Trim().Equals("Often")) { beverage_score = 0; } else if (Beverages != null && Beverages.Trim().Equals("Sometimes")) { beverage_score = 5; } else if (Beverages != null && Beverages.Trim().Equals("Rarely")) { beverage_score = 10; } #endregion double total_score = 0, score_percent = 0; if (total_items != 0) { total_score = (fruit_score + veg_score + fish_score + wg_score + fastfood_score + sweets_score + beverage_score) / total_items; score_percent = total_score * 10; } return(score_percent); }
public void Add(Sweet sweet) { Sweets.Add(sweet); Weight += sweet.Weight; }