Advertisement
svetlyoek

Untitled

Jun 17th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. namespace HealthyHeaven
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. public class Restaurant
  9. {
  10. private List<Salad> data;
  11.  
  12. private string name;
  13.  
  14. public Restaurant(string name)
  15. {
  16. this.name = name;
  17. this.data = new List<Salad>();
  18. }
  19.  
  20. public List<Salad> Data
  21. {
  22. get { return this.data; }
  23. set { this.data = value; }
  24. }
  25.  
  26. public string Name
  27. {
  28. get { return this.name; }
  29. set { this.name = value; }
  30. }
  31.  
  32. public void Add(Salad salad)
  33. {
  34. if (!this.data.Contains(salad))
  35. {
  36. this.data.Add(salad);
  37. }
  38. }
  39.  
  40. public bool Buy(string name)
  41. {
  42. if (this.data.Where(x => x.Name == name).ToList().Count > 0)
  43. {
  44. return true;
  45. }
  46. return false;
  47. }
  48.  
  49. public Salad GetHealthiestSalad()
  50. {
  51. return this.data.OrderBy(x => x.GetTotalCalories()).First();
  52. }
  53.  
  54. public string GenerateMenu()
  55. {
  56. StringBuilder sb = new StringBuilder();
  57.  
  58. sb.AppendLine($"{this.Name} have {this.Data.Count} salads:");
  59.  
  60. foreach(var item in this.data)
  61. {
  62. sb.AppendLine(item.ToString());
  63. }
  64.  
  65. return sb.ToString().TrimEnd();
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement