Advertisement
Guest User

Salad

a guest
Jun 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace HealthyHeaven
  6. {
  7. public class Salad
  8. {
  9. private string name;
  10.  
  11. private Vegetable vegetable;
  12.  
  13. private List<Vegetable> list;
  14. public string Name { get; set; }
  15. public Vegetable Vegetable { get; set; }
  16.  
  17. public Salad(string name)
  18. {
  19. this.Name = name;
  20. this.Vegetable = vegetable;
  21. list = new List<Vegetable>();
  22. }
  23.  
  24.  
  25. public int GetTotalCalories()
  26. {
  27. int sum = 0;
  28. foreach (var item in list)
  29. {
  30. sum += item.Calories;
  31. }
  32. return sum;
  33. }
  34.  
  35. public int GetProductCount()
  36. {
  37. return list.Count;
  38. }
  39. public void Add(Vegetable vegetable)
  40. {
  41. list.Add(vegetable);
  42. }
  43.  
  44. public override string ToString()
  45. {
  46. StringBuilder sb = new StringBuilder();
  47. sb.AppendLine($"* Salad {this.Name} is {GetTotalCalories()} calories and have {GetProductCount()} products:");
  48. foreach (var item in list)
  49. {
  50. sb.AppendLine($" - {item.Name} have {item.Calories} calories");
  51. }
  52. return sb.ToString();
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement