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;
- using System.Threading.Tasks;
- namespace RegularExam
- {
- internal class FlowerStore
- {
- private string name;
- private List<Flower> flowers;
- public FlowerStore(string name)
- {
- Name = name;
- flowers = new List<Flower>();
- }
- public string Name
- {
- get { return name; }
- set
- {
- if (value.Length < 6)
- {
- throw new ArgumentException("Invalid flower store name!");
- }
- name = value;
- }
- }
- public void AddFlower(Flower flower)
- {
- flowers.Add(flower);
- }
- public bool SellFlower(Flower flower)
- {
- foreach (Flower checkFlower in flowers)
- {
- if (checkFlower.Type == flower.Type && checkFlower.Color == flower.Color && checkFlower.Price == flower.Price)
- {
- flowers.Remove(checkFlower);
- return true;
- }
- }
- return false;
- }
- public double CalculateTotalPrice()
- {
- return flowers.Select(e => e.Price).Sum();
- }
- public Flower GetFlowerWithHighestPrice()
- {
- return flowers.OrderByDescending(e => e.Price).First();
- }
- public Flower GetFlowerWithLowestPrice()
- {
- return flowers.OrderBy(e => e.Price).First();
- }
- public void RenameFlowerStore(string newName)
- {
- Name = newName;
- }
- public void SellAllFlowers()
- {
- flowers.Clear();
- }
- public override string ToString()
- {
- var sb = new StringBuilder();
- if (flowers.Count() > 0)
- {
- sb.Append($"Flower store {name} has {flowers.Count} flower/s:\n");
- sb.Append(string.Join("\n", flowers));
- }
- else
- {
- sb.Append($"Flower store {name} has no available flowers.");
- }
- return sb.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement