Advertisement
ZazoTazo

Lab 12 Employee

Nov 21st, 2020
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.34 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 Project_2
  8. {
  9.     class Employee : Human
  10.     {
  11.         public int ID;
  12.         public float salary;
  13.  
  14.         public Employee(int id, string name, float salary)
  15.         {
  16.             this.name = name;
  17.             ID = id;
  18.             this.salary = salary;
  19.         }
  20.  
  21.         //for icomparable
  22.         //public int CompareTo(object obj)
  23.         //{
  24.         //    Employee e = (Employee)obj;
  25.         //    //return (this.Salary.CompareTo(e.Salary));
  26.         //    if (this.salary == e.salary)
  27.         //    {
  28.         //        return 0;
  29.         //    }
  30.         //    else
  31.         //    {
  32.         //        if (this.salary < e.salary)
  33.         //        {
  34.         //            return -1;
  35.         //        }
  36.         //        else
  37.         //        {
  38.         //            return 1;
  39.         //        }
  40.         //    }
  41.         //}
  42.  
  43.         //public int CompareTo(Employee other)
  44.         //{
  45.         //    return salary.CompareTo(other.salary);
  46.         //}
  47.     }
  48.  
  49.     class EmployeeSort : IComparer<Employee>
  50.     {
  51.         public enum sortBy
  52.         {
  53.             ID,
  54.             name,
  55.             salary
  56.         }
  57.         public sortBy sortChoice = sortBy.salary;
  58.  
  59.         public int Compare(Employee x, Employee y)
  60.         {
  61.             switch (sortChoice)
  62.             {
  63.                 case sortBy.ID:
  64.                     return x.ID.CompareTo(y.ID);
  65.                 case sortBy.name:
  66.                     return x.name.CompareTo(y.name);
  67.                 case sortBy.salary:
  68.                     return x.salary.CompareTo(y.salary);
  69.                 default:
  70.                     Console.WriteLine("Error, invalid choice");
  71.                     break;
  72.             }
  73.             return x.salary.CompareTo(y.salary);
  74.         }
  75.  
  76.         //public int Compare(object x, object y)
  77.         //{
  78.         //    switch (sortChoice)
  79.         //    {
  80.         //        case sortBy.ID:
  81.         //            return ((Employee)x).ID.CompareTo(((Employee)y).ID);
  82.         //        case sortBy.name:
  83.         //            return ((Employee)x).name.CompareTo(((Employee)y).name);
  84.         //        case sortBy.salary:
  85.         //            return ((Employee)x).salary.CompareTo(((Employee)y).salary);
  86.         //        default:
  87.         //            Console.WriteLine("Error, invalid choice");
  88.         //            break;
  89.         //    }
  90.         //    return ((Employee)x).salary.CompareTo(((Employee)y).salary);
  91.         //}
  92.     }
  93.     class EmployeeSortReverse : IComparer<Employee>
  94.     {
  95.         public enum sortBy
  96.         {
  97.             ID,
  98.             name,
  99.             salary
  100.         }
  101.         public sortBy sortChoice = sortBy.salary;
  102.  
  103.         public int Compare(Employee x, Employee y)
  104.         {
  105.             switch (sortChoice)
  106.             {
  107.                 case sortBy.ID:
  108.                     return y.ID.CompareTo(x.ID);
  109.                 case sortBy.name:
  110.                     return y.name.CompareTo(x.name);
  111.                 case sortBy.salary:
  112.                     return y.salary.CompareTo(x.salary);
  113.                 default:
  114.                     Console.WriteLine("Error, invalid choice");
  115.                     break;
  116.             }
  117.             return y.salary.CompareTo(x.salary);
  118.         }
  119.     }
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement