Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Person
- {
- private string name;
- private decimal money;
- private List<Product> products;
- public Person(string name, decimal money)
- {
- this.Name = name;
- this.Money = money;
- products = new List<Product>();
- }
- public List<Product> Products
- {
- get { return products; }
- private set { products = value; }
- }
- public decimal Money
- {
- get { return money; }
- private set
- {
- Validator.ValidatingMoney(value);
- this.money = value;
- }
- }
- public string Name
- {
- get { return name; }
- private set
- {
- Validator.ValidatingName(value);
- this.name = value;
- }
- }
- public void AddProduct(Product product)
- {
- if (product.Cost <= money)
- {
- products.Add(product);
- this.money -= product.Cost;
- }
- else
- {
- throw new ArgumentException($"{name} can't afford {product.Name}");
- }
- }
- public override string ToString()
- {
- return $"{name} - {string.Join(", ", products)}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement