Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Да се създаде клас "Стока", съдържащ име, цена, мерна единица
- // Да се валидира цената
- // Да се добави метод "Отстъпка", който намалява цената според отстъпката
- // Предефинирайте метод ToString, така че да вади името и цената
- using System;
- namespace class1
- {
- public class Product
- {
- //Свойства
- public string Name { get; set; }
- private double price;
- public double Price
- {
- get
- {
- return price;
- }
- set
- {
- if (value < 0 || value > 5000)
- {
- throw new ArgumentException("Invalid price");
- }
- price = value;
- }
- }
- public string Unit { get; set; }
- //Конструктор
- public Product(string name, double price, string unit)
- {
- this.Name = name;
- this.Price = price;
- this.Unit = unit;
- }
- //Методи
- public void Discount(double percentage)
- {
- Price -= Price * percentage / 100;
- }
- //Предефинирани методи
- public override string ToString()
- {
- return string.Format("{0}: {1:f2} lv", Name, Price);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement