Advertisement
Guest User

Untitled

a guest
Oct 29th, 2017
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class Pizza
  6. {
  7.     private string name;
  8.     private Dough dough;
  9.     private List<Topping> toppings;
  10.  
  11.     public Pizza(string name, Dough dough, List<Topping> toppings)
  12.     {
  13.         Name = name;
  14.         Dough = dough;
  15.         Toppings = toppings;
  16.     }
  17.  
  18.     public string Name
  19.     {
  20.         get
  21.         {
  22.             return name;
  23.         }
  24.         set
  25.         {
  26.             if (string.IsNullOrEmpty(value) || value.Length > 15)
  27.             {
  28.                 throw new ArgumentException("Pizza name should be between 1 and 15 symbols.");
  29.             }
  30.             name = value;
  31.         }
  32.     }
  33.  
  34.     public List<Topping> Toppings
  35.     {
  36.         get
  37.         {
  38.             return toppings;
  39.         }
  40.         set
  41.         {
  42.             if (value.Count > 10)
  43.             {
  44.                 throw new ArgumentException("Number of toppings should be in range [0..10].");
  45.             }
  46.             toppings = value; // comment this
  47.         }
  48.     }
  49.  
  50.     public Dough Dough
  51.     {
  52.         get
  53.         {
  54.             return dough;
  55.         }
  56.         set
  57.         {
  58.             dough = value;
  59.         }
  60.     }
  61.  
  62.     public double CalculateTotalCalories()
  63.     {
  64.         return dough.CalculateCalories() + toppings.Sum(t => t.CalculateCalorys());
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement