Advertisement
Guest User

Topping

a guest
Jul 30th, 2019
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 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 Topping
  9. {
  10. private const double MinWeight = 1;
  11. private const double MaxWeight = 50;
  12.  
  13. private const double meat = 1.2;
  14. private const double veggies = 0.8;
  15. private const double cheese = 1.1;
  16. private const double sauce = 0.9;
  17.  
  18. private string name;
  19. private double weight;
  20.  
  21. public Topping(string name, double weight)
  22. {
  23. this.Name = name;
  24. this.Weight = weight;
  25. }
  26.  
  27. public string Name
  28. {
  29. get => this.name;
  30. set
  31. {
  32. if (value.ToLower() != "meat" && value.ToLower() != "veggies" &&
  33. value.ToLower() != "cheese" && value.ToLower() != "sauce")
  34. {
  35. throw new InvalidOperationException(String.Format
  36. (Exceptions.InvalidToppingNameException, value));
  37. }
  38. this.name = value;
  39. }
  40. }
  41.  
  42. public double Weight
  43. {
  44. get => this.weight;
  45. set
  46. {
  47. if (value < MinWeight || value > MaxWeight)
  48. {
  49. throw new InvalidOperationException(String.Format
  50. (Exceptions.InvalidToppingWeightException, this.Name));
  51. }
  52. this.weight = value;
  53. }
  54. }
  55.  
  56. public double CalculateCalories()
  57. {
  58. double calories = 0.0;
  59.  
  60. switch (Name.ToLower())
  61. {
  62. case "meat": calories = 2 * this.Weight * meat; break;
  63. case "veggies": calories = 2 * this.Weight * veggies; break;
  64. case "cheese": calories = 2 * this.Weight * cheese; break;
  65. case "sauce": calories = 2 * this.Weight * sauce; break;
  66. default:
  67. break;
  68. }
  69.  
  70. return calories;
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement