Advertisement
Guest User

Untitled

a guest
Nov 7th, 2021
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  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 NameMinLength = 1;
  11. private const int NameMaxLength = 15;
  12.  
  13. private const int MaxRangeToppings = 10;
  14.  
  15. private string name;
  16. private Dough dough;
  17. private List<Topping> toppings;
  18.  
  19. public Pizza(string name, Dough dough)
  20. {
  21. this.Name = name;
  22. this.dough = dough;
  23. toppings = new List<Topping>();
  24. }
  25.  
  26. public string Name
  27. {
  28. get => this.name;
  29. private set
  30. {
  31. if (value.Length < NameMinLength || value.Length > NameMaxLength)
  32. {
  33. throw new ArgumentException($"Pizza name should be between {NameMinLength} and {NameMaxLength} symbols.");
  34.  
  35. }
  36. this.name = value;
  37. }
  38. }
  39.  
  40. public void AddTopping(Topping topping)
  41. {
  42. if (this.toppings.Count == MaxRangeToppings)
  43. {
  44. throw new InvalidOperationException($"Number of toppings should be in range [0..{MaxRangeToppings}].");
  45. }
  46. this.toppings.Add(topping);
  47. }
  48. public double GetCalories()
  49. {
  50. return this.dough.GetCalories() + this.toppings.Sum(t => t.GetCalories());
  51. }
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement