Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace HealthyHeaven
- {
- public class Salad
- {
- private string name;
- private Vegetable vegetable;
- private List<Vegetable> list;
- public string Name { get; set; }
- public Vegetable Vegetable { get; set; }
- public Salad(string name)
- {
- this.Name = name;
- this.Vegetable = vegetable;
- list = new List<Vegetable>();
- }
- public int GetTotalCalories()
- {
- int sum = 0;
- foreach (var item in list)
- {
- sum += item.Calories;
- }
- return sum;
- }
- public int GetProductCount()
- {
- return list.Count;
- }
- public void Add(Vegetable vegetable)
- {
- list.Add(vegetable);
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine($"* Salad {this.Name} is {GetTotalCalories()} calories and have {GetProductCount()} products:");
- foreach (var item in list)
- {
- sb.AppendLine($" - {item.Name} have {item.Calories} calories");
- }
- return sb.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement