Advertisement
Guest User

Untitled

a guest
Nov 7th, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace PizzaCalories
  6. {
  7. public class Topping
  8. {
  9. private const int MinWeight = 1;
  10. private const int MaxWeight = 50;
  11.  
  12. private string name;
  13. private int weight;
  14.  
  15. public Topping(string name, int weight)
  16. {
  17. Name = name;
  18. Weight = weight;
  19. }
  20.  
  21. public string Name
  22. {
  23. get => this.name;
  24. private set
  25. {
  26. var valueAsLower = value.ToLower();
  27. if (valueAsLower != "meat" && valueAsLower != "veggies" && valueAsLower != "cheese" && valueAsLower != "sauce")
  28. {
  29. throw new ArgumentException($"Cannot place {value} on top of your pizza.");
  30. }
  31. this.name = value;
  32. }
  33. }
  34. public int Weight
  35. {
  36. get => this.weight;
  37. private set
  38. {
  39. Validator.ThrowIfNumberIsNotInRange(MinWeight, MaxWeight, value, $"{this.Name} weight should be in the range[{MinWeight}..{MaxWeight}].");
  40. this.weight = value;
  41. }
  42. }
  43.  
  44. public double GetCalories()
  45. {
  46. var modifier = GetModifier();
  47. return this.Weight * 2 * modifier;
  48. }
  49.  
  50. private double GetModifier()
  51. {
  52. var modifierLower = this.Name.ToLower();
  53. if (modifierLower == "meat")
  54. {
  55. return 1.2;
  56. }
  57.  
  58. if (modifierLower == "veggies")
  59. {
  60. return 0.8;
  61. }
  62. if (modifierLower == "cheese")
  63. {
  64. return 1.1;
  65. }
  66. return 0.9;
  67. }
  68. }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement