Exemplo n.º 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}");
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            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");

            Cohort cohort1 = new Cohort("Cohort 33");
            Cohort cohort2 = new Cohort("Cohort 34");
            Cohort cohort3 = new Cohort("Cohort 35");

            Student FortunatoMugnano = new Student("Fortunato", "Mugnano", "fortunato-mugnano", cohort1);
            Student DavidCornish     = new Student("David", "Cornish", "david-cornish", cohort2);
            Student HeidiSmith       = new Student("Heidi", "Smith", "heidi-smith", cohort3);
            Student PhilGrass        = new Student("Phil", "Grass", "phil-grass", cohort3);
            Student MarkLong         = new Student("Mark", "Long", "mark-long", cohort1);
            Student NickRiviera      = new Student("Nick", "Riviera", "nick-riviera", cohort2);

            Instructor AdamSheaffer = new Instructor("Adam", "Sheaffer", "adam-sheaffer", "back-end", cohort1);
            Instructor BrendaLong   = new Instructor("Brenda", "Long", "brenda-long", "front-end", cohort2);
            Instructor MoSilvera    = new Instructor("Mo", "Silvera", "mo-silvera", "front-end", cohort3);
            Instructor MadyPiper    = new Instructor("Mady", "Piper", "madi-piper", "back-end", cohort3);

            cohort1.StudentList.Add(FortunatoMugnano);
            cohort1.StudentList.Add(MarkLong);
            cohort2.StudentList.Add(DavidCornish);
            cohort3.StudentList.Add(HeidiSmith);
            cohort3.StudentList.Add(PhilGrass);
            cohort2.StudentList.Add(NickRiviera);

            cohort1.InstructorList.Add(AdamSheaffer);
            cohort2.InstructorList.Add(BrendaLong);
            cohort3.InstructorList.Add(MoSilvera);
            cohort3.InstructorList.Add(MadyPiper);

            AdamSheaffer.AssignExercise(FortunatoMugnano, exercise1);
            BrendaLong.AssignExercise(DavidCornish, exercise2);
            MoSilvera.AssignExercise(HeidiSmith, exercise3);
            AdamSheaffer.AssignExercise(PhilGrass, exercise4);
            AdamSheaffer.AssignExercise(FortunatoMugnano, exercise5);

            List <Student> students = new List <Student>();

            students.Add(FortunatoMugnano);
            students.Add(DavidCornish);
            students.Add(HeidiSmith);
            students.Add(PhilGrass);
            students.Add(MarkLong);
            students.Add(NickRiviera);

            List <Exercise> exercises = new List <Exercise>();

            exercises.Add(exercise1);
            exercises.Add(exercise2);
            exercises.Add(exercise3);
            exercises.Add(exercise4);
            exercises.Add(exercise5);

            foreach (Student student in students)
            {
                Console.WriteLine($"Student: {student._firstName} {student._lastName}");
                Console.WriteLine("Exercises:");
                foreach (Exercise exercise in student.Exercises)
                {
                    Console.WriteLine($"Program: {exercise.Name} Language: {exercise.Language}");
                }
            }

            List <Cohort> cohorts = new List <Cohort>()
            {
                cohort1,
                cohort2,
                cohort3,
            };

            List <Instructor> instructor = new List <Instructor>()
            {
                AdamSheaffer,
                MoSilvera,
                BrendaLong,
                MadyPiper
            };

            List <Exercise> javascriptExercise = exercises.Where(ex => ex.Language == "JS").ToList();

            foreach (var item in javascriptExercise)
            {
                Console.WriteLine(item.Name);
            }

            var listOfStudentsInCohort = cohorts.Where(cohort => cohort.Name == "Cohort 35")
                                         .SelectMany(c => c.StudentList).Distinct().ToList();

            foreach (var item in listOfStudentsInCohort)
            {
                Console.WriteLine($"{item._firstName} {item._lastName} is in Cohort 35");
            }

            var listOfInstructors = cohorts.Where(c => c.Name == "Cohort 35").SelectMany(c => c.InstructorList).Distinct().ToList();

            foreach (var item2 in listOfInstructors)
            {
                Console.WriteLine($"{item2._firstName} {item2._lastName}: Instructors assigned for cohort-35");
            }

            var studentsByLastName = students.OrderBy(x => x._lastName).ToList();

            foreach (var item3 in studentsByLastName)
            {
                Console.WriteLine(item3._lastName);
            }

            var studentWithoutExercises = students.Where(student => student.Exercises.Count == 0).ToList();

            foreach (var item4 in studentWithoutExercises)
            {
                Console.WriteLine($"These student does't have any exercise assigned: {item4._firstName} {item4._lastName}");
            }

            var studentWithMostExercises = students.Select(student => new
            {
                firstName         = student._firstName,
                lastName          = student._lastName,
                numberOfExercises = student.Exercises.Count()
            }).OrderByDescending(x => x.numberOfExercises).FirstOrDefault();

            Console.WriteLine($"The student with the most exercises: {studentWithMostExercises.firstName} {studentWithMostExercises.lastName} with {studentWithMostExercises.numberOfExercises} exercises");

            var numOfStudents = cohorts.Select(x => new
            {
                name = x.Name,
                numOfStudentsInCohort = x.StudentList.Count()
            }).ToList();

            foreach (var item5 in numOfStudents)
            {
                Console.WriteLine($"In {item5.name} there are {item5.numOfStudentsInCohort} students.");
            }
        }
Exemplo n.º 3
0
 public void assignExercise(Student student, Exercise singleExercise)
 {
     student.Exercises.Add(singleExercise);
 }
Exemplo n.º 4
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.");
            }
        }