Guest User

Pizza

a guest
Jul 30th, 2019
389
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace PizzaCalories
  7. {
  8. public class Pizza
  9. {
  10. private const int MaxLength = 15;
  11. private const int MaxToppingCount = 10;
  12. private const int MinToppingCount = 0;
  13.  
  14. private string name;
  15. private Dough dough;
  16. private readonly List<Topping> toppings;
  17.  
  18. public Pizza(string name, Dough dough)
  19. {
  20. this.Name = name;
  21. this.Dough = dough;
  22.  
  23. this.toppings = new List<Topping>();
  24. }
  25.  
  26. public string Name
  27. {
  28. get => this.name;
  29. set
  30. {
  31. if (value.Length > MaxLength || string.IsNullOrWhiteSpace(value))
  32. {
  33. throw new ArgumentException(Exceptions.InvalidPizzaNameException);
  34. }
  35. this.name = value;
  36. }
  37. }
  38.  
  39. public Dough Dough { get; set; }
  40.  
  41. public void AddTopping(Topping topping)
  42. {
  43. if (this.toppings.Count < MinToppingCount || this.toppings.Count > MaxToppingCount)
  44. {
  45. throw new ArgumentException(Exceptions.InvalidToppingCountException);
  46. }
  47. this.toppings.Add(topping);
  48. }
  49.  
  50. public override string ToString()
  51. {
  52. double calories = this.Dough.CalculateCalories() + this.toppings.Sum(t => t.CalculateCalories());
  53. return $"{this.Name} - {calories:F2} Calories.";
  54. }
  55. }
  56. }
RAW Paste Data