svetlyoek

Untitled

Jul 8th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. namespace PizzaCalories
  2. {
  3. using System;
  4. public class Topping
  5. {
  6. private const double MAX_WEIGHT = 50;
  7. private const double MIN_WEIGHT = 0;
  8.  
  9. private const double meat = 1.2;
  10. private const double veggies = 0.8;
  11. private const double cheese = 1.1;
  12. private const double sauce = 0.9;
  13.  
  14. private string name;
  15. private double weight;
  16.  
  17. public Topping(string name, double weight)
  18. {
  19. this.Name = name;
  20. this.Weight = weight;
  21. }
  22. public string Name
  23. {
  24. get
  25. {
  26. return this.name;
  27. }
  28. private set
  29. {
  30. if (value.ToLower() != "meat" && value.ToLower() != "veggies" && value.ToLower() != "cheese" && value.ToLower() != "sauce")
  31. {
  32. throw new ArgumentException(string.Format(ExceptionMessages.Exception.invalidToppingNameException, value));
  33. }
  34.  
  35. this.name = value;
  36. }
  37. }
  38.  
  39. public double Weight
  40. {
  41. get
  42. {
  43. return this.weight;
  44. }
  45.  
  46. private set
  47. {
  48. if (value < MIN_WEIGHT || value > MAX_WEIGHT)
  49. {
  50. throw new ArgumentException(string.Format(ExceptionMessages.Exception.invalidToppingWeightException,this.Name));
  51. }
  52.  
  53. this.weight = value;
  54. }
  55. }
  56.  
  57. public double CalculateCalories()
  58. {
  59. double calories = 0.0;
  60.  
  61. if (this.Name == "meat")
  62. {
  63. calories = 2 * (this.weight * meat);
  64. }
  65.  
  66. else if (this.Name == "veggies")
  67. {
  68. calories = 2 * (this.weight * veggies);
  69. }
  70.  
  71. else if (this.Name == "cheese")
  72. {
  73. calories = 2 * (this.weight * cheese);
  74. }
  75.  
  76. else if (this.Name == "sauce")
  77. {
  78. calories = 2 * (this.weight * sauce);
  79. }
  80.  
  81. return calories;
  82. }
  83. }
  84. }
Add Comment
Please, Sign In to add comment