Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace RegularExam_UASD
- {
- internal class CoffeeShop
- {
- //полета -> характеристики
- private string name;
- private List<Coffee> coffees;
- public CoffeeShop()
- {
- //нов празен обект
- //name = null
- //coffees = null
- }
- public CoffeeShop(string name)
- {
- //нов празен обект
- this.name = name;
- this.coffees = new List<Coffee>();
- }
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- public List<Coffee> Coffees
- {
- get
- {
- return coffees;
- }
- set
- {
- coffees = value;
- }
- }
- public void AddCoffee(string name, double price)
- {
- Coffee coffee = new Coffee(name, price);
- coffees.Add(coffee);
- }
- public double AveragePriceInRange(double start, double end)
- {
- //кафета с цени между start и end
- int count = 0;
- double sum = 0;
- foreach(Coffee coffee in coffees)
- {
- if (coffee.Price >= start && coffee.Price <= end)
- {
- count++;
- sum += coffee.Price;
- }
- }
- //сумата от цената на кафетата
- //брой на кафетата
- return sum / count;
- }
- public List<string> RemoveCoffeesByPrice(double price)
- {
- List<String> leftCoofees = new List<string>(); // имената на кафетата с по-малка цена от дадената
- foreach (Coffee coffee in coffees)
- {
- if (coffee.Price < price)
- {
- leftCoofees.Add(coffee.Type);
- }
- }
- return leftCoofees;
- }
- public List<Coffee> SortAscendingByType()
- {
- return coffees.OrderBy(coffee => coffee.Type).ToList();
- }
- public List<Coffee> SortDescendingByPrice()
- {
- return coffees.OrderByDescending(coffee => coffee.Price).ToList();
- }
- public bool CheckCoffeeIsInCoffeeShop(string type)
- {
- //true -> ако имаме такова кафе
- //false -> ако нямаме такова кафе
- foreach(Coffee coffee in coffees)
- {
- if (coffee.Type == type)
- {
- return true;
- }
- }
- return false;
- }
- public string[] ProvideInformationAboutAllCoffees()
- {
- List<string> infoList = new List<string>();
- foreach (Coffee coffee in coffees)
- {
- infoList.Add(coffee.ToString());
- }
- return infoList.ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement