Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ExamPreparation
- {
- class Fridge
- {
- private List<Product> products;
- private int count;
- public Fridge()
- {
- count = 0;
- products = new List<Product>();
- }
- public int Count
- {
- get
- {
- return count;
- }
- set
- {
- count = value;
- }
- }
- public void AddProduct(string productName)
- {
- //1. създадем продукт
- Product productToAdd = new Product(productName);
- //2. добавим
- products.Add(productToAdd);
- }
- public string[] CookMeal(int start, int end)
- {
- //[a, b, c, d, e, f, j]
- List<string> foundProducts = new List<string>();
- if (end > products.Count - 1)
- {
- end = products.Count - 1;
- }
- for (int index = start; index <= end; index++)
- {
- foundProducts.Add(products[index].Name);
- }
- return foundProducts.ToArray();
- }
- public string RemoveProductByIndex(int index)
- {
- //1. взимаме продукта от индекса
- Product productToRemove = products[index];
- //2. премахваме го
- if (products.Remove(productToRemove))
- {
- return productToRemove.Name;
- }
- else
- {
- return null;
- }
- }
- public string RemoveProductByName(string name)
- {
- for (int i = 0; i < products.Count; i++)
- {
- if (name == products[i].Name)
- {
- if (products.Remove(products[i]))
- {
- return name;
- }
- else
- {
- //няма го продукта
- return null;
- }
- }
- }
- return null;
- }
- public bool CheckProductIsInStock(string name)
- {
- foreach (Product product in products)
- {
- if (product.Name == name)
- {
- return true;
- }
- }
- return false;
- }
- public string[] ProvideInformationAboutAllProducts()
- {
- List<string> info = new List<string>();
- foreach (Product product in products)
- {
- info.Add(product.ToString());
- }
- return info.ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement