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()
- {
- }
- public CoffeeShop(string name)
- {
- Name = name;
- 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 type, double price)
- {
- Coffee coffee = new Coffee(type, price);
- Coffees.Add(coffee);
- }
- public double AveragePriceInRange(double start, double end)
- {
- double sum = 0;
- int count = 0;
- foreach (Coffee coffee in Coffees)
- {
- if (coffee.Price >= start && coffee.Price <= end)
- {
- sum += coffee.Price;
- count++;
- }
- }
- return sum / count;
- }
- public List<string> FilterCoffeesByPrice(double price)
- {
- List<String> leftCoffees = new List<String>();
- foreach (Coffee coffee in Coffees)
- {
- if (coffee.Price < price)
- {
- leftCoffees.Add(coffee.Type);
- }
- }
- return leftCoffees;
- }
- public List<Coffee> SortAscendingByType()
- {
- List<Coffee> sorted = Coffees.OrderBy(coffee => coffee.Type).ToList();
- Coffees = sorted;
- return sorted;
- }
- public List<Coffee> SortDescendingByPrice()
- {
- List<Coffee> sorted = Coffees.OrderByDescending(coffee => coffee.Price).ToList();
- Coffees = sorted;
- return sorted;
- }
- public bool CheckCoffeeIsInCoffeeShop(string type)
- {
- 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