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
- {
- internal class HatShop
- {
- private string name;
- private List<Hat> hats;
- public HatShop(string name)
- {
- Name = name;
- hats = new List<Hat>();
- }
- public string Name
- {
- get { return name; }
- set
- {
- if (value.Length < 6)
- {
- throw new ArgumentException("Invalid hat shop name!");
- }
- name = value;
- }
- }
- public void AddHat(Hat Hat)
- {
- this.hats.Add(Hat);
- }
- public bool SellHat(Hat Hat)
- {
- foreach (Hat checkHat in this.hats)
- {
- if (checkHat.Type == Hat.Type && checkHat.Color == Hat.Color && checkHat.Price == Hat.Price)
- {
- this.hats.Remove(checkHat);
- return true;
- }
- }
- return false;
- }
- public double CalculateTotalPrice()
- {
- return this.hats.Select(e => e.Price).Sum();
- }
- public Hat GetHatWithHighestPrice()
- {
- return this.hats.OrderByDescending(e => e.Price).First();
- }
- public Hat GetHatWithLowestPrice()
- {
- return this.hats.OrderBy(e => e.Price).First();
- }
- public void RenameHatShop(string newName)
- {
- Name = newName;
- }
- public void SellAllHats()
- {
- this.hats.Clear();
- }
- public override string ToString()
- {
- var sb = new StringBuilder();
- if (this.hats.Count() > 0)
- {
- sb.Append($"Hat shop {name} has {this.hats.Count} hat/s:\n");
- sb.Append(string.Join("\n", this.hats));
- }
- else
- {
- sb.Append($"Hat shop {name} has no available hats.");
- }
- return sb.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement