Пример #1
0
        static void Main(string[] args)
        {
            Cohort cohort32 = new Cohort("Cohort 32");
            Cohort cohort33 = new Cohort("Cohort 33");
            Cohort cohort34 = new Cohort("Cohort 34");
            Cohort cohort35 = new Cohort("Cohort 35");

            Student student1 = new Student("Nick", "Wessel", "wesseln1", cohort32);
            Student student2 = new Student("Dave", "Cornish", "heidi1", cohort32);
            Student student3 = new Student("Heidi", "Smith", "smith1", cohort32);
            Student student4 = new Student("Mark", "McCann", "mccann1", cohort33);
            Student student5 = new Student("Seth", "Williams", "willIam", cohort34);
            Student student6 = new Student("Keaton", "Heights", "higherThanKeaton", cohort34);
            Student student7 = new Student("Phil", "Philly", "PhillyPhil", cohort35);
            Student student8 = new Student("Stephan", "Walgreens", "Walgreens1", cohort35);
            Student student9 = new Student("James", "Kay", "KayJames", cohort35);

            Instructor AdamSheaffer = new Instructor("Adam", "Sheaffer", "adam-sheaffer", "back-end", cohort32);
            Instructor BrendaLong   = new Instructor("Brenda", "Long", "brenda-long", "front-end", cohort33);
            Instructor MoSilvera    = new Instructor("Mo", "Silvera", "mo-silvera", "front-end", cohort34);
            Instructor MadiPiper    = new Instructor("Mady", "Piper", "madi-piper", "back-end", cohort35);

            Exercise exercise1 = new Exercise("Create a for each loop.", "JS");
            Exercise exercise2 = new Exercise("Stylize the index.", "CSS");
            Exercise exercise3 = new Exercise("Develop an app.", "React");
            Exercise exercise4 = new Exercise("Build a website.", "HTML");
            Exercise exercise5 = new Exercise("Study If Else stataments", "JS");

            List <Student> students = new List <Student>()
            {
                student1,
                student2,
                student3,
                student4,
                student5,
                student6,
                student7,
                student8,
                student9
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                cohort32,
                cohort33,
                cohort34,
                cohort35
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                AdamSheaffer,
                BrendaLong,
                MadiPiper,
                MoSilvera
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                exercise1,
                exercise2,
                exercise3,
                exercise4,
                exercise5
            };

            cohort32.CohortStudents.Add(student1);
            cohort32.CohortStudents.Add(student2);
            cohort32.CohortStudents.Add(student3);
            cohort33.CohortStudents.Add(student4);
            cohort34.CohortStudents.Add(student5);
            cohort34.CohortStudents.Add(student6);
            cohort35.CohortStudents.Add(student7);
            cohort35.CohortStudents.Add(student8);
            cohort35.CohortStudents.Add(student9);

            cohort32.CohortInstructors.Add(AdamSheaffer);
            cohort33.CohortInstructors.Add(BrendaLong);
            cohort34.CohortInstructors.Add(MoSilvera);
            cohort35.CohortInstructors.Add(MadiPiper);

            AdamSheaffer.AssignExercise(student1, exercise5);
            AdamSheaffer.AssignExercise(student1, exercise3);
            AdamSheaffer.AssignExercise(student2, exercise1);
            AdamSheaffer.AssignExercise(student3, exercise1);
            BrendaLong.AssignExercise(student4, exercise2);
            MoSilvera.AssignExercise(student5, exercise3);
            MoSilvera.AssignExercise(student6, exercise3);
            MadiPiper.AssignExercise(student7, exercise4);
            MadiPiper.AssignExercise(student8, exercise4);

            Console.WriteLine();
            Console.WriteLine("Student Reports");
            foreach (var student in students)
            {
                Console.WriteLine($"Student: {student.FirstName} {student.LastName}");
                Console.WriteLine($"From: {student.Cohort.Name}");
                Console.WriteLine();
                foreach (var exercise in student.StudentExercises)
                {
                    Console.WriteLine($"Exercise: {exercise.Name}");
                    Console.WriteLine($"Language: {exercise.Language}");
                    Console.WriteLine();
                }

                List <Exercise> javaScriptExercises = exercises.Where(exercise => exercise.Language == "JS").ToList();

                foreach (var exercise in javaScriptExercises)
                {
                    Console.WriteLine($"{exercise.Name} is a {exercise.Language} language!");
                }

                List <Student> cohortStudents = students.Where(student => student.Cohort.Name == "Cohort 35").ToList();

                Console.WriteLine($"Cohort Student List: ");
                Console.WriteLine();
                foreach (var cohortStudent in cohortStudents)
                {
                    Console.WriteLine($"{cohortStudent.FirstName} {cohortStudent.LastName}");
                    Console.WriteLine();
                }

                List <Instructor> cohortInstructors = instructors.Where(instructor => instructor.Cohort.Name == "Cohort 35").ToList();

                Console.WriteLine($"Instructor: ");
                foreach (var cohortInstructor in cohortInstructors)
                {
                    Console.WriteLine($"{cohortInstructor.FirstName} {cohortInstructor.LastName}");
                    Console.WriteLine();
                }

                var orderedStudnetList = students.OrderBy(student => student.LastName);

                foreach (var s in orderedStudnetList)
                {
                    Console.WriteLine($"{s.LastName}, {s.FirstName}");
                }
                Console.WriteLine();

                var noExercises = students.Where(student => student.StudentExercises.Count == 0);

                Console.WriteLine("Currently no exercises assigned:");
                foreach (var s in noExercises)
                {
                    Console.WriteLine($"{s.FirstName} {s.LastName}");
                }

                var studentWithMostExercises = students.Select(student => new
                {
                    firstName         = student.FirstName,
                    lastName          = student.LastName,
                    numberOfExercises = student.StudentExercises.Count()
                }).OrderByDescending(ex => ex.numberOfExercises).FirstOrDefault();

                Console.WriteLine();
                Console.WriteLine($"{studentWithMostExercises.firstName} {studentWithMostExercises.lastName} has the most active assignments!");

                foreach (var cohort in cohorts)
                {
                    Console.WriteLine();
                    Console.WriteLine($"{cohort.Name}:");
                    Console.WriteLine($"{cohort.CohortStudents.Count}");
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var ExerciseList   = new List <Exercise>();
            var FizzBuzz       = new Exercise("Fizz Buzz", "JavaScript");
            var Journal        = new Exercise("Journal", "HTML");
            var DiamondCutter  = new Exercise("Diamond Cutter", "Ruby");
            var GetYourGlasses = new Exercise("Get Your Glasses", "C#");

            var Day32   = new Cohort("Day Cohort 32");
            var Night10 = new Cohort("Night Cohort 10");
            var Day13   = new Cohort("Day Cohort 13");

            var Bryan  = new Student("Bryan", "Nilsen", "@BryanNilsen", "Day Cohort 13");
            var Ricky  = new Student("Ricky", "McConnell", "@Rickydogsickdog", "Day Cohort 32");
            var Julian = new Student("Julian", "Swayze", "@Juls", "Night Cohort 10");
            var Corey  = new Student("Corey", "Trevor", "@CoreyTrevor", "Day Cohort 32");
            var Randy  = new Student("Randy", "Lahey", "@Randers", "Night Cohort 10");

            var Steve = new Instructor("Steve", "Brownlee", "@SteveCoach", "Dad Jokes", "Day Cohort 32");
            var Adam  = new Instructor("Adam", "Schaeffer", "@AdamShaef", "Snacks", "Day Cohort 13");
            var Andy  = new Instructor("Andy", "Collins", "@AndyBoBandy", "Dancing", "Night Cohort 10");

            Steve.AssignExercise(Ricky, FizzBuzz);
            Steve.AssignExercise(Bryan, DiamondCutter);

            Adam.AssignExercise(Corey, GetYourGlasses);
            Adam.AssignExercise(Julian, Journal);

            Andy.AssignExercise(Ricky, GetYourGlasses);
            Andy.AssignExercise(Corey, DiamondCutter);

            Ricky.ViewAssignedExercises();
            Bryan.ViewAssignedExercises();
            Julian.ViewAssignedExercises();
            Corey.ViewAssignedExercises();

            Day13.StudentList.Add(Bryan);
            Day32.StudentList.Add(Ricky);
            Day32.StudentList.Add(Corey);
            Night10.StudentList.Add(Julian);

            Console.WriteLine("------------------");
            foreach (Student student in Day32.StudentList)
            {
                Console.WriteLine($"Day Cohort 32: {student.FirstName}");
            }

            Console.WriteLine("------------------");
            foreach (Student student in Night10.StudentList)
            {
                Console.WriteLine($"Night Cohort 10: {student.FirstName}");
            }

            Console.WriteLine("------------------");
            foreach (Student student in Day13.StudentList)
            {
                Console.WriteLine($"Day Cohort 13: {student.FirstName}");
                Console.WriteLine("");
            }

            var AllStudents = new List <Student>();

            AllStudents.Add(Bryan);
            AllStudents.Add(Ricky);
            AllStudents.Add(Julian);
            AllStudents.Add(Corey);
            AllStudents.Add(Randy);

            var AllExercises = new List <Exercise>();

            AllExercises.Add(FizzBuzz);
            AllExercises.Add(Journal);
            AllExercises.Add(DiamondCutter);
            AllExercises.Add(GetYourGlasses);

            var AllInstructors = new List <Instructor>();

            AllInstructors.Add(Steve);
            AllInstructors.Add(Adam);
            AllInstructors.Add(Andy);

            var AllCohorts = new List <Cohort>();

            AllCohorts.Add(Day32);
            AllCohorts.Add(Day13);
            AllCohorts.Add(Night10);

            // List exercises for the JavaScript language by using the Where() LINQ method.
            List <Exercise> JSExercises = (from exercise in AllExercises
                                           where exercise.Language == "JavaScript"
                                           select exercise).ToList();

            foreach (Exercise exer in JSExercises)
            {
                Console.WriteLine($"List of JS exercises: {exer.Name}");
            }

            // List students in a particular cohort by using the Where() LINQ method.
            List <Student> StudentsInCohort = (from student in AllStudents
                                               where student._cohort == "Day Cohort 32"
                                               select student).ToList();

            foreach (Student stu in StudentsInCohort)
            {
                Console.WriteLine($"Students in Day Cohort 32: {stu.FirstName} {stu.LastName}");
            }

            // List instructors in a particular cohort by using the Where() LINQ method.
            List <Instructor> InstructorInCohort = (from instructor in AllInstructors
                                                    where instructor._cohort == "Night Cohort 10"
                                                    select instructor).ToList();

            foreach (Instructor inst in InstructorInCohort)
            {
                Console.WriteLine($"Instructor of the Cohort: {inst.FirstName} {inst.LastName}");
            }

            // Sort the students by their last name.
            List <Student> OrderStudent = AllStudents.OrderBy(s => s.LastName).ToList();

            foreach (Student stu in OrderStudent)
            {
                Console.WriteLine($"All student ordered by last name: {stu.LastName} {stu.FirstName}");
            }

            // Display any students that aren't working on any exercises.
            var NoExercises = (from student in AllStudents
                               where student.ExerciseList.Count == 0
                               select student);

            foreach (Student stu in NoExercises)
            {
                Console.WriteLine($"Students with no exercises: {stu.FirstName} {stu.LastName}");
            }

            // Which student is working on the most exercises
            var MostExercises = AllStudents.OrderByDescending(student =>
                                                              student.ExerciseList.Count()).Take(2);

            foreach (Student s in MostExercises)
            {
                Console.WriteLine($"Student with most exercises: {s.FirstName} {s.LastName}");
            }

            // How many students in each cohort?
            foreach (var cohort in AllCohorts)
            {
                Console.WriteLine($"{cohort.CohortName}: {cohort.StudentList.Count()} students.");
            }
        }