Advertisement
AskTomorrow

Untitled

Feb 12th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Ismatov_Nozimzhon
  8. {
  9.     public abstract class Item
  10.     {
  11.  
  12.         public Item(string name, double cost, double price)
  13.         {
  14.             this.Name = name;
  15.             this.Cost = cost;
  16.             this.Price = price;
  17.         }
  18.  
  19.         private double cost;
  20.  
  21.         public double Cost
  22.         {
  23.             get
  24.             {
  25.                 return cost;
  26.             }
  27.             private set
  28.             {
  29.                 if (value < 0.0d || value > 999999.0d)
  30.                 {
  31.                     throw new MerchantException($@"Cost = {value} length out of range");
  32.                 }
  33.                 else
  34.                 {
  35.                     cost = value;
  36.                 }
  37.             }
  38.         }
  39.  
  40.         private string name;
  41.  
  42.         public string Name
  43.         {
  44.             get
  45.             {
  46.                 return name;
  47.             }
  48.             private set
  49.             {
  50.                 if (value.Length < 5 || value.Length > 30)
  51.                 {
  52.                     throw new MerchantException($@"Name = {value} length out of range");
  53.                 }
  54.                 else
  55.                 {
  56.                     name = value;
  57.                 }
  58.             }
  59.         }
  60.  
  61.         private double price;
  62.  
  63.         public double Price
  64.         {
  65.             get
  66.             {
  67.                 return price;
  68.             }
  69.             set
  70.             {
  71.                 if (value < 0.0d || value > 999999.0d)
  72.                 {
  73.                     throw new MerchantException($@"Price = {value}  out of range");
  74.                 }
  75.                 else
  76.                 {
  77.                     price = value;
  78.                 }
  79.             }
  80.         }
  81.  
  82.         public override string ToString()
  83.         {
  84.             return $@"Item {Name}: Price = {Price:F2}, Cost = {Cost:F2}";
  85.         }
  86.  
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement