2010/03/29

C# week10_1

29/03/2010

Sorting

 
 

namespace ConsoleApplication23

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Please enter Annual increment");

string a = Console.ReadLine();

int j = int.Parse(a);

Employee.AnnualIncrement=j;

Console.WriteLine(j);

Employee[] e = new Employee[4];

e[0] = new Employee(1, "ABC", 100.00);

e[1] = new Employee(2, "AAA", 200.00);

e[2] = new Employee(3, "XYZ", 500.00);

e[3] = new Employee(4, "CMG", 300.00);


 

foreach (Employee m in e)

{

Console.WriteLine(m.EmployeeName);

}

Array.Sort(e, new Sorting());

 
 

 
 

foreach (Employee n in e)

{

Console.WriteLine(n.EmployeeName+ " " + n.Salary + " "+n.GetAnnualIncrement());


 

}

 
 

}

}

class Employee

{

public int EmployeeID;

public string EmployeeName;

public double Salary;

public static int AnnualIncrement;

 
 

public double GetAnnualIncrement()

{

double inc = Salary*AnnualIncrement/100;

return inc;

}

 
 

public Employee(int id, string name, double salary)

{

EmployeeID =id;

EmployeeName=name;

Salary = salary;

}

}

class Sorting : IComparer

{

 
 

public int Compare(object a, object b)

{

Employee em = (Employee)a;

Employee em1 = (Employee)b;

 
 

double increment = em.GetAnnualIncrement();

double increment1 = em1.GetAnnualIncrement();

 
 

if (increment > increment1)

{

return 10;

}

else

if (increment == increment1)

{

return 0;

}

else

{

return -10;

}


 

}

 
 

}

 
 

}

0 件のコメント:

コメントを投稿

UA-9417263-1