Advertisement
msmilkoff

Computer

Nov 22nd, 2015
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. class Computer
  2.     {
  3.         private string name;
  4.         private List<Component> components;
  5.         private decimal price;
  6.  
  7.         private static decimal TotalComponentsPrice(List<Component> components)
  8.         {
  9.             decimal totalPrice = 0;
  10.             foreach (var cmpt in components)
  11.             {
  12.                 totalPrice += cmpt.Price;
  13.             }
  14.  
  15.             return totalPrice;
  16.         }
  17.  
  18.         public void Init(string name, List<Component> components)
  19.         {
  20.             this.Name = name;
  21.             this.Price = TotalComponentsPrice(components);
  22.             this.Components = components;
  23.         }
  24.  
  25.         public string Name
  26.         {
  27.             get
  28.             {
  29.                 return this.name;
  30.             }
  31.             set
  32.             {
  33.                 if (string.IsNullOrEmpty(value))
  34.                 {
  35.                     throw new ArgumentNullException("Name cannot be empty");
  36.                 }
  37.                 this.name = value;
  38.             }
  39.         }
  40.         public decimal Price
  41.         {
  42.             get
  43.             {
  44.                 return this.price;
  45.             }
  46.             set
  47.             {
  48.                 this.price = TotalComponentsPrice(components);
  49.             }
  50.            
  51.         }
  52.         public List<Component> Components { get; set; }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement