Advertisement
aslen

Untitled

Dec 17th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Salary1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<Employee> myJournal;
  14.             int count = 0;
  15.  
  16.             myJournal = CreateListWorkers();
  17.  
  18.             Console.WriteLine("Salary from this month:\n");
  19.  
  20.             var sortJournal = LINQSort(myJournal);
  21.             foreach (var item in sortJournal)
  22.             {
  23.                 count++;
  24.                 Console.WriteLine("{0}) {1}: {2:C}", count, item.Name, item.Salary);
  25.             }
  26.  
  27.         }
  28.         private static List<Employee> CreateListWorkers()
  29.         {
  30.             List<Employee> workers = new List<Employee>();
  31.  
  32.             workers.Add(new FixedSalary("Roma Mak", 1000));
  33.             workers.Add(new HoursSalary("Ivan Lisov", 4));
  34.             workers.Add(new FixedSalary("Nikolay Murtov", 780));
  35.             workers.Add(new HoursSalary("Svetlana Orekhova", 5.5));
  36.             workers.Add(new FixedSalary("Diana Reva", 610));
  37.             workers.Add(new HoursSalary("Oleg Lugniy", 5));
  38.             workers.Add(new FixedSalary("Dmitriy Stok", 870));
  39.             workers.Add(new HoursSalary("Mila Werhova", 8));
  40.             workers.Add(new FixedSalary("Roma Reakov", 1190));
  41.  
  42.             return workers;
  43.         }
  44.         static IOrderedEnumerable<Employee> LINQSort(List<Employee> journal)
  45.         {
  46.             var sortJournal = from u in journal
  47.                               orderby u.Salary
  48.                               select u;
  49.             return sortJournal;
  50.         }
  51.     }
  52.     abstract class Employee
  53.     {
  54.         public string Name { get; set; }
  55.         public double Tax { get; set; }
  56.         public double Salary { get; set; }
  57.         public Employee(string name, double tax)
  58.         {
  59.             this.Name = name;
  60.             this.Tax = tax;
  61.             averageSalary();
  62.         }
  63.  
  64.         protected abstract void averageSalary();
  65.  
  66.     }
  67.     class FixedSalary : Employee
  68.     {
  69.         public FixedSalary(string name, double salary)
  70.             : base(name, salary)
  71.         { }
  72.         protected override void averageSalary()
  73.         {
  74.             Salary = Tax;
  75.         }
  76.     }
  77.     class HoursSalary : Employee
  78.     {
  79.         private const double rate = 20.8;
  80.         private double hourOfDays = 8;
  81.  
  82.         public HoursSalary(string name, double salary)
  83.             : base(name, salary)
  84.         { }
  85.  
  86.         protected override void averageSalary()
  87.         {
  88.             Salary = rate * hourOfDays * Tax;
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement