Exemplo n.º 1
0
 static void Main(string[] args)
 {
     var rd = new Random();
     var students = new Student[10];
     var workers = new Worker[10];
     for (int i = 0; i < 10; i++)
     {
         students[i] = new Student("Alex", "Alex", rd.Next(10000, 99999).ToString());
         workers[i] = new Worker("Alex", "Alex", rd.NextDouble() * 999, rd.Next(1, 8));
     }
     var sortedStudents = students.OrderBy(x => x.FaultyNumber);
     var sortedWorkers = workers.OrderByDescending(x => x.MoneyPerHour());
     var humans = sortedStudents.Cast<Human>()
         .Union(sortedWorkers)
         .OrderBy(x => x.FirstName)
         .ThenBy(x => x.LastName);
 }
        static void Main()
        {
            var testWorker = new Worker("Ivan", "Georgiev", 290.20, 8);
            var moneyPerHour = testWorker.MoneyPerHour();
            //Console.WriteLine(moneyPerHour);

            // Testing Student
            var albenova = new Student("Anna", "Albenova", 11111);
            var dimitrova = new Student("Petya", "Dimitrova", 11112);
            var denkova = new Student("Denica", "Denkova", 11113);
            var marks = new Student("Jennifer", "Marks", 11114);
            var unugugu = new Student("Ogonogo", "Unugugu", 11123);
            var kim = new Student("Yao", "Kim", 12311);
            var james = new Student("Dennis", "James", 12317);
            var heat = new Student("Phil", "Heat", 12316);
            var green = new Student("Kai", "Green", 12319);
            var coleman = new Student("Ronnie", "Coleman", 12318);

            var students = new List<Student>() { albenova, dimitrova, denkova, marks, unugugu, kim, james, heat, 
                                                 green, coleman };

            //Console.WriteLine("Students, unsorted:\n");
            //foreach (var student in students)
            //{
            //    Console.WriteLine("-----------------------\nFirst Name: {0}\nLast Name: {1}\nFaculty Number: {2}" +
            //                      "\n-----------------------\n", 
            //                      student.FirstName, student.LastName, student.FacultyNumber);
            //}

            var sortedStudents =
                from student in students
                orderby student.FacultyNumber
                select student;

            //Console.WriteLine("Students, sorted by Faculty Number:\n");
            //foreach (var sortedStudent in sortedStudents)
            //{
            //    Console.WriteLine("-----------------------\nFirst Name: {0}\nLast Name: {1}\nFaculty Number: {2}" +
            //                      "\n-----------------------\n",
            //                      sortedStudent.FirstName, sortedStudent.LastName, sortedStudent.FacultyNumber);
            //}

            // Testing Worker

            var worker1 = new Worker("Georgi", "Georgiev", 220.99, 8);
            var worker2 = new Worker("Alfonso", "Gomez", 120.99, 7);
            var worker3 = new Worker("Lui", "Fines", 323.50, 8);
            var worker4 = new Worker("Romul", "Remov", 420.50, 8);
            var worker5 = new Worker("Rosen", "Gacov", 330.99, 8);
            var worker6 = new Worker("Kosym", "Kosymchov", 122.99, 6);
            var worker7 = new Worker("Bliznak", "Bliznakov", 186.90, 12);
            var worker8 = new Worker("Petar", "Tudjarov", 125.00, 8);
            var worker9 = new Worker("Pope", "Popov", 170.00, 8);
            var worker10 = new Worker("Martin", "Georgiev", 150.00, 8);

            var workers = new List<Worker>()
            {
                worker1,
                worker2,
                worker3,
                worker4,
                worker5,
                worker6,
                worker7,
                worker8,
                worker9,
                worker10
            };

            var sortedWorkers = workers.OrderByDescending(p => p.MoneyPerHour());

            //Console.WriteLine("Workers sorted by payment per hour in descending order:\n");
            //foreach (var sortedWorker in sortedWorkers)
            //{
            //    Console.WriteLine("-----------------------\nFirst Name: {0}\nLast Name: {1}\nWeek Salary: {2}" +
            //                      "\nWork Hours per Day: {3}\nMoney per Hour: {4}" +
            //                      "\n-----------------------\n",
            //                      sortedWorker.FirstName, sortedWorker.LastName, 
            //                      sortedWorker.WeekSalary, sortedWorker.WorkHoursPerDay, 
            //                      sortedWorker.MoneyPerHour());
            //}

            var humans = new List<Human>();
            humans.AddRange(students);
            humans.AddRange(workers);
            var sortedHumans = humans.OrderBy(h => h.FirstName).ThenBy(h => h.LastName);

            Console.WriteLine("Sorted humans:\n");
            foreach (var sortedHuman in sortedHumans)
            {
                Console.WriteLine("First Name: {0}\nLast Name: {1}\n", sortedHuman.FirstName, sortedHuman.LastName);
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            try
            {
                Student student = new Student("Test", "Test1", "number1234");
                Worker worker = new Worker("Test", "Worker", 500.00m, 8);

                Console.WriteLine(student);
                Console.WriteLine(worker);
                Console.WriteLine("*************************************************************************");

                List<Student> students = new List<Student>
                {
                    new Student("Ivan", "Ivanov", "fn00000006"),
                    new Student("Nikola", "Nikolov", "fn00000002"),
                    new Student("Georgi", "Georgiev", "fn00000008"),
                    new Student("Stefan", "Stefanov", "fn00000010"),
                    new Student("Todor", "Todorov", "fn00000005"),
                    new Student("Pesho", "Peshev", "fn00000001"),
                    new Student("Marin", "Marinov", "fn00000007"),
                    new Student("Angel", "Angelov", "fn00000003"),
                    new Student("Borislav", "Borisov", "fn00000009"),
                    new Student("Savo", "Savov", "fn00000004")
                };

                students = students.OrderBy(c => c.FacultyNumber).ToList();

                foreach (var st in students)
                {
                    Console.WriteLine(st);
                }

                Console.WriteLine("*************************************************************************");
                List<Worker> workers = new List<Worker>
                {
                    new Worker("Ivan", "Angelov", 430.00m, 6),
                    new Worker("Nikola", "Nikolov", 236.23m, 4),
                    new Worker("Georgi", "Georgiev", 530.13m, 10),
                    new Worker("Stefan", "Stefanov", 140m, 4),
                    new Worker("Todor", "Todorov", 524m, 8),
                    new Worker("Pesho", "Peshev", 325.13m, 6),
                    new Worker("Marin", "Marinov", 1049m, 10),
                    new Worker("Angel", "Angelov", 670m, 5),
                    new Worker("Borislav", "Borisov", 831.4m, 6),
                    new Worker("Savo", "Savov", 314.23m, 5)
                };
                workers = workers.OrderByDescending(c => c.MoneyPerHour()).ToList();

                foreach (var wk in workers)
                {
                    Console.WriteLine(wk);
                }

                Console.WriteLine("*************************************************************************");
                List<Human> humans = new List<Human>();
                humans.AddRange(students);
                humans.AddRange(workers);
                humans = humans.OrderBy(c => c.FirstName).ThenBy(c => c.LastName).ToList();

                foreach (var human in humans)
                {
                    Console.WriteLine(human);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }            
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var pesho = new Student("pesho", "petrov", "20144567");
            var gosho = new Student("gosho", "georgiev", "20141730");
            var misho = new Student("misho", "mishev", "20142589");
            var ganka = new Student("ganka", "gancheva", "20146547");
            var sanya = new Student("sanya", "mincheva", "20145285");
            var ivan = new Student("ivan", "ivanov", "20145687");
            var dimitar = new Student("dimitar", "dimitrov", "20143698");
            var damyan = new Student("damyan", "damyanov", "20149634");
            var mihail = new Student("mihail", "petrov", "20147415");

            var doncho = new Student("doncho", "donchev", "20145612");

            var students = new List<Student>()
            {
                pesho,
                gosho,
                misho,
                ganka,
                sanya,
                ivan,
                dimitar, 
                damyan,
                mihail,
                doncho
            };

            Console.WriteLine("Sorted Students:");
            var sortedStudents = students.OrderBy(st => st.FacultyNumber);
            foreach (var stud in sortedStudents)
            {
                Console.WriteLine("{0} {1} - {2}", stud.FirstName, stud.LastName, stud.FacultyNumber);
            }

            var kosta = new Worker("kosta", "kostadinov", 282m, 8f);
            var sancho = new Worker("sancho", "pansa", 382m, 6.5f);
            var penka = new Worker("penka", "kostadinova", 243m, 4.75f);
            var dimitrichka = new Worker("dimitrichka", "doynova", 152m, 2.75f);
            var darina = new Worker("darina", "stamatova", 182m, 5.5f);
            var zlatomir = new Worker("zlatomir", "zlatev", 242m, 7.5f);
            var petar = new Worker("petar", "donchev", 482m, 6f);
            var pencho = new Worker("pencho", "kubadinski", 578m, 9f);
            var marko = new Worker("marko", "totev", 439m, 8f);
            var kostadin = new Worker("kostadin", "haralambov", 658m, 9f);

           var workers = new List<Worker>()
            {
                kosta,
                sancho,
                penka,
                dimitrichka,
                darina,
                zlatomir,
                petar,
                pencho,
                marko,
                kostadin
            };

            Console.WriteLine("\nSorted Workers: ");
            var sortedWorkers = workers.OrderByDescending(w => w.MoneyPerHour(5));
            foreach (var worker in sortedWorkers)
            {
                Console.WriteLine("{0} {1} - {2:N2}", worker.FirstName, worker.LastName, worker.MoneyPerHour(5));
            }

            Console.WriteLine("\nSorted Humans: ");
            var humans = new List<Human>();
            humans.AddRange(students);
            humans.AddRange(workers);

            var sortedHumans = humans.OrderBy(h => h.FirstName).ThenBy(h => h.LastName);
            foreach (var human in sortedHumans)
            {
                Console.WriteLine("{0} {1}", human.FirstName, human.LastName);
            }
        }