Advertisement
Guest User

Untitled

a guest
Nov 7th, 2021
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace PizzaCalories
  6. {
  7. public class Dough
  8. {
  9. private const int MinWeight = 1;
  10. private const int MaxWeight = 200;
  11.  
  12. private string flourType;
  13. private int weight;
  14. private string bakingTechnique;
  15.  
  16. public Dough(string flourType, string bakingTechnique, int weight)
  17. {
  18. FlourType = flourType;
  19. BakingTechnique = bakingTechnique;
  20. Weight = weight;
  21. }
  22.  
  23. public string FlourType
  24. {
  25. get => this.flourType;
  26. private set
  27. {
  28. var valueAsLower = value.ToLower();
  29. if (valueAsLower != "white" && valueAsLower != "wholegrain")
  30. {
  31. throw new ArgumentException("Invalid type of dough.");
  32. }
  33. this.flourType = value;
  34. }
  35. }
  36. public string BakingTechnique
  37. {
  38. get => this.bakingTechnique;
  39. private set
  40. {
  41. var valueAsLower = value.ToLower();
  42. if (valueAsLower != "crispy" && valueAsLower != "chewy" && valueAsLower != "homemade")
  43. {
  44. throw new ArgumentException("Invalid type of dough.");
  45. }
  46. this.bakingTechnique = value;
  47. }
  48. }
  49. public int Weight
  50. {
  51. get => this.weight;
  52. private set
  53. {
  54. Validator.ThrowIfNumberIsNotInRange(MinWeight, MaxWeight, value, $"Dough weight should be in the range [{MinWeight}..{MaxWeight}].");
  55. this.weight = value;
  56. }
  57. }
  58.  
  59. public double GetCalories()
  60. {
  61. var flourTypeModifier = GetFlourTypeModifier();
  62. var bakingModifier = GetBakingModifier();
  63.  
  64. return this.Weight * 2 * flourTypeModifier * bakingModifier;
  65. }
  66.  
  67. private double GetBakingModifier()
  68. {
  69. var bakingLower = this.BakingTechnique.ToLower();
  70. if (bakingLower == "crispy")
  71. {
  72. return 0.9;
  73. }
  74.  
  75. if (bakingLower == "chewy")
  76. {
  77. return 1.1;
  78. }
  79. return 1;
  80. }
  81.  
  82. private double GetFlourTypeModifier()
  83. {
  84. var flourTypeLower = this.FlourType.ToLower();
  85. if (flourTypeLower == "white")
  86. {
  87. return 1.5;
  88. }
  89.  
  90. return 1;
  91. }
  92. }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement