Advertisement
desislava_topuzakova

Employee.cs

May 9th, 2020
1,212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Exam_Preparation1
  6. {
  7.     public class Employee
  8.     {
  9.         private string name;
  10.         private double salary;
  11.  
  12.         public string Name
  13.         {
  14.             get
  15.             {
  16.                 return name;
  17.             }
  18.             set
  19.             {
  20.                 if(value.Length < 3)
  21.                 {
  22.                     throw ArgumentException("Invalid name");
  23.                 }
  24.                 name = value;
  25.             }
  26.         }
  27.  
  28.         private Exception ArgumentException(string v)
  29.         {
  30.             throw new NotImplementedException();
  31.         }
  32.  
  33.         public double Salary
  34.         {
  35.             get
  36.             {
  37.                 return salary;
  38.             }
  39.             set
  40.             {
  41.                 if(value < 560)
  42.                 {
  43.                     throw ArgumentException("Invalid salary");
  44.                 }
  45.                 salary = value;
  46.             }
  47.         }
  48.         public Employee(string name, double salary)
  49.         {
  50.             Name = name;
  51.             Salary = salary;
  52.         }
  53.  
  54.         public override string ToString()
  55.         {
  56.             //обект на стринг
  57.             //Employee: < име > with salary < заплата >
  58.             return $"Employee: {name} with salary {salary:F2}";
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement