Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // We have two types of workers in our company(we’ll have
- // more in the future) -??????????????? ТУК ДАЛИ НЕ СТАВА ВЪПРОС ЗА ИНТЕРФЕЙС ???????????????
- //Driver
- //Welder
- //Create classes to describe those.They should have the
- //following properties: age(between 18 and 60), tenure, name
- //(max 50 symbols), sex, salary(positive numbers only) and
- //allowed time off.And the following behaviours (methods) –
- //say hello, weld and drive (respectively for each worker type).
- //Create 10 instances of the Driver class add them to an array.
- //Iterate them and get the 5 oldest and put them into a list.
- //Iterate the list and print their tenure and name;
- class Program
- {
- static void Main(string[] args)
- {
- var newWorker = new Worker();
- newWorker.Age = 15;
- newWorker.Name = "Ivan";
- Console.WriteLine(newWorker.Age);
- Console.WriteLine(newWorker.Name);
- newWorker.Salary = -199;
- newWorker.SayHello();
- Console.WriteLine(newWorker.Salary);
- var newDriver = new Driver();
- newDriver.Name = "Atanas";
- newDriver.SayHello();
- Driver[] driverArr = new Driver[10];
- }
- }
- class Worker
- {
- private int age; //between 18 and 60
- private int tenure;
- private string name; //max 50 symbols
- private bool isMale;
- private int salary; //positive number only
- private int timeOff; //
- public Worker()
- {
- }
- public Worker(int age, int tenure, string name, bool isMale, int salary, int timeOff)
- {
- this.age = age;
- this.tenure = tenure;
- this.name = name;
- this.isMale = isMale;
- this.salary = salary;
- this.timeOff = timeOff;
- }
- public virtual void SayHello()
- {
- Console.WriteLine($"Hello! I am a Worker! And my name is: {this.name}");
- }
- public int Age
- {
- get
- {
- try
- {
- if (age < 18 || age > 60)
- {
- throw new IndexOutOfRangeException();
- }
- }
- catch (IndexOutOfRangeException a)
- {
- Console.WriteLine("This person is not able to work according to the law!");
- return 0;
- }
- return this.age;
- }
- set { this.age = value; }
- }
- public int Tenure
- {
- get { return this.tenure; }
- set { this.tenure = value; }
- }
- public string Name
- {
- get
- {
- try
- {
- if (name.Length > 50)
- {
- throw new ArgumentOutOfRangeException();
- }
- }
- catch(ArgumentOutOfRangeException e)
- {
- Console.WriteLine("Name can't contain more than 50 characters.");
- return null;
- }
- return this.name;
- }
- set { this.name = value; }
- }
- public bool IsMale
- {
- get { return this.isMale; }
- set { this.isMale = value; }
- }
- public int Salary
- {
- get
- {
- try
- {
- if (salary <= 0)
- {
- throw new IndexOutOfRangeException();
- }
- }
- catch(IndexOutOfRangeException e)
- {
- Console.WriteLine("You must enter a positive integer!");
- return 0;
- }
- return this.salary;
- }
- set { this.salary = value; }
- }
- public int TimeOff
- {
- get { return this.timeOff; }
- set { this.timeOff = value; }
- }
- }
- class Driver: Worker
- {
- public Driver():base()
- {
- }
- public Driver(int age, int tenure, string name, bool isMale, int salary, int timeOff):base(age, tenure,name,isMale,salary,timeOff)
- {
- }
- public override void SayHello()
- {
- Console.WriteLine($"Hello! I am a driver! My name is: {Name}");
- }
- }
- }
- class Welder:Worker
- {
- public Welder():base()
- {
- }
- public Welder(int age, int tenure, string name, bool isMale, int salary, int timeOff) :base(age, tenure, name, isMale, salary, timeOff)
- {
- }
- public override void SayHello()
- {
- Console.WriteLine($"I am a Welder! And my name is :{Name}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement