Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- var newPerson = new Person();
- newPerson.Age = 15;
- Console.WriteLine(newPerson.Age);
- newPerson.Name = "kasjdajskdksadjkasjkdaksjdkajkd";
- Console.WriteLine(newPerson.Name);
- var newWorker = new Worker();
- newWorker.Name = "doasjdjasdojaodoaodaoj";
- Console.WriteLine(newWorker.Name);
- newWorker.Salary = -100010;
- Console.WriteLine(newWorker.Salary);
- }
- }
- }
- class Person
- {
- private int age;
- private string name;
- public Person()
- {
- }
- public Person(int age, string name)
- {
- this.Age = age;
- this.Name = name;
- }
- public virtual void SayHello()
- {
- Console.WriteLine($"Hello! My name is {Name}");
- }
- public int Age
- {
- get { return this.age; }
- set
- {
- try
- {
- if (value < 18 || value > 60)
- {
- throw new ArgumentException();
- }
- }
- catch(ArgumentException e)
- {
- Console.WriteLine("Invalid age!");
- }
- this.age = value;
- }
- }
- public string Name
- {
- get { return this.name; }
- set
- {
- try
- {
- if(value.Length>15)
- {
- throw new ArgumentException();
- }
- }
- catch(ArgumentException e)
- {
- Console.WriteLine("Invalid Name!");
- }
- this.name = value;
- }
- }
- }
- }
- class Worker : Person
- {
- private int tenure;
- private decimal salary;
- private int timeOff;
- public Worker()
- {
- }
- public Worker(int tenure, decimal salary, int timeOff) : base()
- {
- this.Tenure = tenure;
- this.Salary = salary;
- this.TimeOff = timeOff;
- }
- public override void SayHello()
- {
- Console.WriteLine($"Hello! I am a worker and my name is {Name}");
- }
- public int Tenure
- {
- get { return this.tenure; }
- set { this.tenure = value; }
- }
- public decimal Salary
- {
- get { return this.salary; }
- set
- {
- try
- {
- if (value < 0)
- {
- throw new ArgumentException();
- }
- }
- catch (ArgumentException e)
- {
- Console.WriteLine("Salary can't be a negative number!");
- }
- this.salary = value;
- }
- }
- public int TimeOff
- {
- get { return this.timeOff; }
- set { this.timeOff = value; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement