Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Computer
- {
- private string name;
- private List<Component> components;
- private decimal price;
- private static decimal TotalComponentsPrice(List<Component> components)
- {
- decimal totalPrice = 0;
- foreach (var cmpt in components)
- {
- totalPrice += cmpt.Price;
- }
- return totalPrice;
- }
- public void Init(string name, List<Component> components)
- {
- this.Name = name;
- this.Price = TotalComponentsPrice(components);
- this.Components = components;
- }
- public string Name
- {
- get
- {
- return this.name;
- }
- set
- {
- if (string.IsNullOrEmpty(value))
- {
- throw new ArgumentNullException("Name cannot be empty");
- }
- this.name = value;
- }
- }
- public decimal Price
- {
- get
- {
- return this.price;
- }
- set
- {
- this.price = TotalComponentsPrice(components);
- }
- }
- public List<Component> Components { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement