Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace abstractClass_06_06_2017
- {
- class Program
- {
- interface IWorker
- {
- string Name { get; set; }
- string Surname { get; set; }
- void SetSalary(int a);
- void PaySalary();
- }
- interface IManager
- {
- int ManagerAdd { get; set; }
- }
- abstract class Worker : IWorker
- {
- private string _name;
- private string _surname;
- private int _salary;
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
- public string Surname
- {
- get { return _surname; }
- set { _surname = value; }
- }
- public int Salary
- {
- get { return _salary; }
- set
- {
- if (value > 0)
- _salary = value;
- else
- _salary = 2000;
- }
- }
- public void SetSalary(int p = 2000) { Salary = p; }
- public virtual void PaySalary() { Console.Write($"Salary to pay: {Salary} zł"); }
- public Worker()
- {
- SetSalary();
- }
- }
- class Manager : Worker, IWorker, IManager
- {
- private int _managerAdd;
- private int _monthlyBonus;
- public int ManagerAdd
- {
- get { return _managerAdd; }
- set
- {
- if (value > 0)
- _managerAdd = value;
- else
- _managerAdd = 2000;
- }
- }
- public int MonthlyBonus
- {
- get { return _monthlyBonus; }
- set
- {
- if (value > 0)
- _monthlyBonus = value;
- else
- _monthlyBonus = 1000;
- }
- }
- public override void PaySalary()
- {
- Console.WriteLine($"Salary to pay: {Salary + ManagerAdd + MonthlyBonus} zł");
- }
- public Manager()
- {
- ManagerAdd = 2000;
- MonthlyBonus = 1000;
- }
- }
- class Seller : Worker
- {
- private int _monthlyBonus;
- public int MonthlyBonus
- {
- get { return _monthlyBonus; }
- set
- {
- if (value > 0)
- _monthlyBonus = value;
- else
- _monthlyBonus = 500;
- }
- }
- public override void PaySalary()
- {
- base.PaySalary();
- Console.Write($" and additional {MonthlyBonus} zł monthly bonus");
- }
- public Seller()
- {
- MonthlyBonus = 500;
- }
- }
- static void Main(string[] args)
- {
- Manager manager = new Manager();
- manager.PaySalary();
- Seller seller = new Seller();
- seller.PaySalary();
- Console.ReadKey();
- }
- } //
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement