Advertisement
svetlyoek

Untitled

Jul 8th, 2019
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. namespace PizzaCalories
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. public class Pizza
  7. {
  8. private const int MAX_LENGTH = 15;
  9. private const int MIN_LENGTH = 1;
  10. private const int MAX_TOPPING_COUNT = 15;
  11. private const int MIN_TOPPING_COUNT = 0;
  12.  
  13. private string name;
  14. private Dough dough;
  15. private readonly List<Topping> toppings;
  16.  
  17. public Pizza(string name, Dough dough)
  18. {
  19. this.Name = name;
  20. this.Dough = dough;
  21. this.toppings = new List<Topping>();
  22. }
  23.  
  24. public string Name
  25. {
  26. get
  27. {
  28. return this.name;
  29. }
  30. private set
  31. {
  32. if (value.Length > MAX_LENGTH || string.IsNullOrWhiteSpace(value))
  33. {
  34. throw new ArgumentException(ExceptionMessages.Exception.invalidPizzaNameException);
  35. }
  36.  
  37. this.name = value;
  38. }
  39. }
  40.  
  41. public Dough Dough
  42. {
  43. get
  44. {
  45. return this.dough;
  46. }
  47. private set
  48. {
  49. this.dough = value;
  50. }
  51. }
  52.  
  53.  
  54. public void AddTopping(Topping topping)
  55. {
  56. if (this.toppings.Count == MAX_TOPPING_COUNT)
  57. {
  58. throw new ArgumentException(ExceptionMessages.Exception.invalidToppingNumberException);
  59. }
  60.  
  61. this.toppings.Add(topping);
  62. }
  63.  
  64. public override string ToString()
  65. {
  66. double calories = this.Dough.CalculateCalories() + this.toppings.Sum(t => t.CalculateCalories());
  67. return $"{this.Name} - {calories:f2} Calories.";
  68. }
  69.  
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement