SHARE
TWEET

Untitled

a guest Jan 24th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // We have two types of workers in our company(we’ll have
  2. // more in the future) -??????????????? ТУК ДАЛИ НЕ СТАВА ВЪПРОС ЗА ИНТЕРФЕЙС ???????????????
  3.  
  4. //Driver
  5.  
  6. //Welder
  7.  
  8. //Create classes to describe those.They should have the
  9. //following properties: age(between 18 and 60), tenure, name
  10. //(max 50 symbols), sex, salary(positive numbers only) and
  11. //allowed time off.And the following behaviours (methods) –
  12. //say hello, weld and drive (respectively for each worker type).
  13.  
  14. //Create 10 instances of the Driver class add them to an array.
  15. //Iterate them and get the 5 oldest and put them into a list.
  16. //Iterate the list and print their tenure and name;
  17.     class Program
  18.     {
  19.         static void Main(string[] args)
  20.         {
  21.  
  22.             var newWorker = new Worker();
  23.             newWorker.Age = 15;
  24.             newWorker.Name = "Ivan";
  25.             Console.WriteLine(newWorker.Age);
  26.             Console.WriteLine(newWorker.Name);
  27.             newWorker.Salary = -199;
  28.             newWorker.SayHello();
  29.             Console.WriteLine(newWorker.Salary);
  30.  
  31.             var newDriver = new Driver();
  32.             newDriver.Name = "Atanas";
  33.             newDriver.SayHello();
  34.  
  35.             Driver[] driverArr = new Driver[10];
  36.  
  37.         }
  38.     }
  39.  
  40.   class Worker
  41.     {
  42.         private int age; //between 18 and 60
  43.         private int tenure;
  44.         private string name; //max 50 symbols
  45.         private bool isMale;
  46.         private int salary; //positive number only
  47.         private int timeOff; //
  48.  
  49.         public Worker()
  50.         {
  51.  
  52.         }
  53.         public Worker(int age, int tenure, string name, bool isMale, int salary, int timeOff)
  54.         {
  55.             this.age = age;
  56.             this.tenure = tenure;
  57.             this.name = name;
  58.             this.isMale = isMale;
  59.             this.salary = salary;
  60.             this.timeOff = timeOff;
  61.         }
  62.         public virtual void SayHello()
  63.         {
  64.             Console.WriteLine($"Hello! I am a Worker! And my name is: {this.name}");
  65.         }
  66.         public int Age
  67.         {
  68.             get
  69.             {
  70.                 try
  71.                 {
  72.                     if (age < 18 || age > 60)
  73.                     {
  74.                         throw new IndexOutOfRangeException();
  75.                     }
  76.                 }
  77.                 catch (IndexOutOfRangeException a)
  78.                 {
  79.                     Console.WriteLine("This person is not able to work according to the law!");
  80.                     return 0;
  81.                 }
  82.                 return this.age;
  83.             }
  84.             set { this.age = value; }
  85.         }
  86.         public int Tenure
  87.         {
  88.             get { return this.tenure; }
  89.             set { this.tenure = value; }
  90.         }
  91.  
  92.         public string Name
  93.         {
  94.             get
  95.             {
  96.                 try
  97.                 {
  98.                     if (name.Length > 50)
  99.                     {
  100.                         throw new ArgumentOutOfRangeException();
  101.                     }
  102.                 }
  103.                 catch(ArgumentOutOfRangeException e)
  104.                 {
  105.                     Console.WriteLine("Name can't contain more than 50 characters.");
  106.                     return null;
  107.                 }
  108.                 return this.name;
  109.             }
  110.             set { this.name = value; }
  111.         }
  112.  
  113.         public bool IsMale
  114.         {
  115.             get { return this.isMale; }
  116.             set { this.isMale = value; }
  117.         }
  118.  
  119.         public int Salary
  120.         {
  121.             get
  122.             {
  123.                 try
  124.                 {
  125.                     if (salary <= 0)
  126.                     {
  127.                         throw new IndexOutOfRangeException();
  128.                        
  129.                     }
  130.                 }
  131.                 catch(IndexOutOfRangeException e)
  132.                 {
  133.                     Console.WriteLine("You must enter a positive integer!");
  134.                     return 0;
  135.                 }
  136.                 return this.salary;
  137.             }
  138.             set { this.salary = value; }
  139.         }
  140.         public int TimeOff
  141.         {
  142.             get { return this.timeOff; }
  143.             set { this.timeOff = value; }
  144.         }
  145.        
  146.     }
  147.  
  148.  class Driver: Worker
  149.     {
  150.         public Driver():base()
  151.         {
  152.  
  153.         }
  154.         public Driver(int age, int tenure, string name, bool isMale, int salary, int timeOff):base(age, tenure,name,isMale,salary,timeOff)
  155.         {
  156.  
  157.         }
  158.         public override void SayHello()
  159.         {
  160.             Console.WriteLine($"Hello! I am a driver! My name is: {Name}");
  161.         }
  162.     }
  163. }
  164.  class Welder:Worker
  165.     {
  166.         public Welder():base()
  167.         {
  168.  
  169.         }
  170.         public Welder(int age, int tenure, string name, bool isMale, int salary, int timeOff) :base(age, tenure, name, isMale, salary, timeOff)
  171.         {
  172.  
  173.         }
  174.         public override void SayHello()
  175.         {
  176.             Console.WriteLine($"I am a Welder! And my name is :{Name}");
  177.         }
  178.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top