Advertisement
aslen

Untitled

Dec 17th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.90 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.             myJournal.Sort();
  22.             myJournal.Reverse();
  23.             foreach (var item in myJournal)
  24.             {
  25.                 count++;
  26.                 Console.WriteLine("{0}) {1}: {2:C}", count, item.Name, item.Salary);
  27.             }
  28.  
  29.         }
  30.         private static List<Employee> CreateListWorkers()
  31.         {
  32.             List<Employee> workers = new List<Employee>();
  33.  
  34.             workers.Add(new FixedSalary("Roma Mak", 1000));
  35.             workers.Add(new HoursSalary("Ivan Lisov", 4));
  36.             workers.Add(new FixedSalary("Nikolay Murtov", 780));
  37.             workers.Add(new HoursSalary("Svetlana Orekhova", 5.5));
  38.             workers.Add(new FixedSalary("Diana Reva", 610));
  39.             workers.Add(new HoursSalary("Oleg Lugniy", 5));
  40.             workers.Add(new FixedSalary("Dmitriy Stok", 1190));
  41.             workers.Add(new HoursSalary("Mila Werhova", 8));
  42.             workers.Add(new FixedSalary("Roma Reakov", 1190));
  43.  
  44.             return workers;
  45.         }
  46.         //static IOrderedEnumerable<Employee> LINQSort(List<Employee> journal)
  47.         //{
  48.         //    var sortJournal = from u in journal
  49.         //                      orderby u.Salary descending
  50.         //                      select u;
  51.         //    return sortJournal;
  52.         //}
  53.     }
  54.     abstract class Employee : IComparable<Employee>
  55.     {
  56.         public string Name { get; set; }
  57.         public double Tax { get; set; }
  58.         public double Salary { get; set; }
  59.         public Employee(string name, double tax)
  60.         {
  61.             this.Name = name;
  62.             this.Tax = tax;
  63.             averageSalary();
  64.         }
  65.  
  66.         protected abstract double averageSalary();
  67.  
  68.         public int CompareTo(Employee obj)
  69.         {
  70.             return this.Salary.CompareTo(obj.Salary);
  71.         }
  72.     }
  73.     class FixedSalary : Employee
  74.     {
  75.         public FixedSalary(string name, double salary)
  76.             : base(name, salary)
  77.         { }
  78.         protected override double averageSalary()
  79.         {
  80.             Salary = Tax;
  81.             return Salary;
  82.         }
  83.     }
  84.     class HoursSalary : Employee
  85.     {
  86.         private const double rate = 20.8;
  87.         private double hourOfDays = 8;
  88.  
  89.         public HoursSalary(string name, double salary)
  90.             : base(name, salary)
  91.         { }
  92.  
  93.         protected override double averageSalary()
  94.         {
  95.             Salary = rate * hourOfDays * Tax;
  96.             return Salary;
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement