Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ismatov_Nozimzhon
- {
- public abstract class Item
- {
- public Item(string name, double cost, double price)
- {
- this.Name = name;
- this.Cost = cost;
- this.Price = price;
- }
- private double cost;
- public double Cost
- {
- get
- {
- return cost;
- }
- private set
- {
- if (value < 0.0d || value > 999999.0d)
- {
- throw new MerchantException($@"Cost = {value} length out of range");
- }
- else
- {
- cost = value;
- }
- }
- }
- private string name;
- public string Name
- {
- get
- {
- return name;
- }
- private set
- {
- if (value.Length < 5 || value.Length > 30)
- {
- throw new MerchantException($@"Name = {value} length out of range");
- }
- else
- {
- name = value;
- }
- }
- }
- private double price;
- public double Price
- {
- get
- {
- return price;
- }
- set
- {
- if (value < 0.0d || value > 999999.0d)
- {
- throw new MerchantException($@"Price = {value} out of range");
- }
- else
- {
- price = value;
- }
- }
- }
- public override string ToString()
- {
- return $@"Item {Name}: Price = {Price:F2}, Cost = {Cost:F2}";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement