コード例 #1
0
ファイル: SULSTest.cs プロジェクト: nok32/SoftUni
        public static void Main()
        {
            Person test1 = new Person("Test1", "Test", 20);
            Trainer test2 = new Trainer("Test2", "Test", 20);
            JuniorTrainer test3 = new JuniorTrainer("Test3", "Test", 20);
            SeniorTrainer test4 = new SeniorTrainer("Test4", "Test", 20);
            GraduateStudent test5 = new GraduateStudent("Test5", "Test", 20, "123", 5.23d);
            DropoutStudent test6 = new DropoutStudent("Test6", "Test", 20, "123", 4.23d, "Low average grade");
            CurrentStudent test7 = new CurrentStudent("Test7", "Test", 20, "123", 5.48d, "OOP");
            OnlineStudent test8 = new OnlineStudent("Test8", "Test", 20, "123", 5.48d, "OOP");
            OnsiteStudent test9 = new OnsiteStudent("Test9", "Test", 20, "123", 3.23d, "OOP", 2);

            test2.CreateCourse("OOP");
            test3.CreateCourse("OOP");
            test4.DeleteCourse("OOP");

            List<Person> persons = new List<Person>() { test1, test2, test3, test4, test5, test6, test7, test8, test9 };
          
            var currentStudents = persons
                            .Where(person => person is CurrentStudent) 
                            .OrderBy(person => ((Student)person).AverageGrade)
                            .Select(person => person);

            foreach (var student in currentStudents)
            {
                Console.WriteLine(student);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var courses = new List <Course>
            {
                new Course("C#"),
                new Course("JavaScript"),
                new Course("ASP.NET MVC"),
                new Course("Database"),
            };

            var trainers = new List <Trainer>
            {
                new JuniorTrainer("Emil", "Ivanov", 19),
                new JuniorTrainer("Grigor", "Dimitrov", 20),
                new SeniorTrainer("Nikolay", "Kostov", 25),
                new SeniorTrainer("Georgi", "Georgiev", 27)
            };

            Console.WriteLine("All Courses: ");
            courses.ForEach(c => Console.WriteLine("-" + c.Name));

            Console.WriteLine();

            var seniorTrainer = new SeniorTrainer("Nasko", "Atanasov", 19);

            //Console.WriteLine("All Courses after adding new one");
            seniorTrainer.CreateCourse("Java", courses);
            //courses.ForEach(c => Console.WriteLine("-" + c.Name));

            Console.WriteLine();

            seniorTrainer.DeleteCourse("C#", courses);
            //Console.WriteLine("All Courses after deleting one");
            Console.WriteLine("All Courses: ");
            courses.ForEach(c => Console.WriteLine("-" + c.Name));
            Console.WriteLine();

            var students = new List <Student>
            {
                new OnlineStudent("Pesho", "Peshov", 24, "1332543", 4.44, "C#"),
                new OnsiteStudent("Gosho", "Goshov", 23, "1453565", 3.33, "Java", 8),
                new OnsiteStudent("Manol", "Georgiec", 26, "1875644", 5.99, "C#", 5),
                new OnsiteStudent("Pavel", "Pavlov", 21, "1987543", 4.99, "C#", 9),
                new DropoutStudent("Kiril", "Kirilov", 24, "13676564", 3.33, "He was very nervous"),
                new GraduateStudent("Preslav", "Nikolaev", 24, "13676564", 6.00),
            };

            var currentStudents = students
                                  .Where(st => st is CurrentStudent)
                                  .OrderBy(st => st.AverageGrade)
                                  .ToList();

            currentStudents.ForEach(Console.WriteLine);
        }
コード例 #3
0
        internal static void Main()
        {
            // test trainer methods
            var juniorTrainer = new JuniorTrainer("Elena", "Bojilova", 24);
            var seniorTrainer = new SeniorTrainer("Filip", "Kolev", 25);

            juniorTrainer.CreateCourse("OOP");
            seniorTrainer.CreateCourse("HQC");
            seniorTrainer.DeleteCourse("OOP");
            Console.WriteLine();

            // test Reapply() method
            var applicant = new DropoutStudent("Prekusnal", "Student", 21, 1222, 3.03, "Murzi me");

            applicant.Reapply();
            Console.WriteLine();

            // Create a list of objects from each class
            var people = new List <Person>
            {
                new JuniorTrainer("Ivan", "Ivanov Jr.", 19),
                new SeniorTrainer("Ivan", "Ivanov Sr.", 45),
                new DropoutStudent("Misho", "Mihaylov", 25, 1234, 3.5, "Mrazim da mislim"),
                new GraduateStudent("Viktor", "Kazakov", 31, 1235, 5.25),
                new OnlineStudent("Elena", "Bojilova", 23, 1236, 5.75, "OOP"),
                new OnlineStudent("Pavleta", "Taseva", 21, 1237, 5.5, "OOP"),
                new OnsiteStudent("Svetlin", "Nakov", 34, 1238, 6, "OOP", 15),
            };

            // Extract only the Current Students, sort them by average grade
            var sortedCurrentStudents =
                people.Where(a => a is CurrentStudent)
                .Cast <CurrentStudent>()
                .OrderBy(a => a.AverageGrade);

            // printing
            Console.WriteLine("List of current students (sorted by average grade):");
            Console.WriteLine();

            foreach (var student in sortedCurrentStudents)
            {
                Console.WriteLine(student);
            }
        }
コード例 #4
0
        public void DeleteCourse(SeniorTrainer trainer, string courseName)
        {
            string wholeName = trainer.FirstName + " " + trainer.LastName;

            Console.WriteLine("The trainer {0} has deleted the course {1}.", wholeName, courseName);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            //Normal Person
            Person normalGosho = new Person("Gosho", "Batka", 15);

            //Trainer
            Trainer Pesho = new Trainer("Pesho", "Ganev", 34);
            Pesho.CreateCourse("C# Fundamentals");
            Pesho.CreateCourse("");
            Pesho.CreateCourse("Java Basics");
            Pesho.CreateCourse("PHP");
            Trainer.ViewCourses();
            Console.WriteLine(new String('-', 40));

            //Senior Trainer
            SeniorTrainer Nakov = new SeniorTrainer("Svetlin", "Nakov");
            Nakov.CreateCourse("Ninja Programmer");
            SeniorTrainer.ViewCourses();
            Nakov.RemoveCourse("Java Basics");
            Nakov.RemoveCourse("DrunDrun");
            Trainer.ViewCourses();
            Console.WriteLine(new String('-', 40));

            //Junior Trainer
            JuniorTrainer Penka = new JuniorTrainer("Penka");

            //Student
            Student Borcho = new Student("Borcho", 5189154, 5.5, "Penchev", 54);

            //Graduate Student
            GraduateStudent Dimitri = new GraduateStudent("Dimitri", 132623453, 4.3);

            //Current Student
            CurrentStudent Bachi = new CurrentStudent("Bachi", 623454235, 3.4, "Math Algorithms");

            //Droput Student 
            DropoutStudent Ivancho = new DropoutStudent("Ivancho", 412341, 2.0, "I can't learn regex expressions");
            Ivancho.Reapply();
            Console.WriteLine(new String('-', 40));

            //Online Student
            OnlineStudent Qwerty = new OnlineStudent("Qwerty", 273485, 4.5, "PHP");

            //Onsite Student
            OnsiteStudent Gencho = new OnsiteStudent("Gencho", 513451, 6.0, "Java", 84);
            OnsiteStudent Mariika = new OnsiteStudent("Mariika", 45634653, 5.9, "JavaScript", 34, "Pencheva", 45);

            List<Person> people = new List<Person>()
	        {
	            Bachi,
                Gencho,
                Mariika,
                Qwerty,
                Penka,
                Borcho,
                Dimitri, 
                Ivancho,
                normalGosho,
                Nakov
	        };

            people.Where(x => x.GetType().BaseType.Name == "CurrentStudent").OrderByDescending(x => ((Student)x).AveGrade).ToList().ForEach(x => Console.WriteLine(x.Name + " -> " + ((Student)x).AveGrade));

        }