コード例 #1
0
ファイル: Program.cs プロジェクト: ImHughes/StudentExercises
        static void Main(string[] args)

        {
            var studentExercise = new Exercise()
            {
                Name     = "Student Exercise",
                Language = "C#"
            };

            var jsExercise = new Exercise()
            {
                Name     = "Chicken Monkey",
                Language = "JavaScript"
            };

            var journal = new Exercise()
            {
                Name     = "Journal",
                Language = "HTML"
            };

            var sqlExercise = new Exercise()
            {
                Name     = "Data",
                Language = "SQL"
            };

            var c30 = new Cohort()
            {
                CohortName = "Day Cohort 30"
            };
            var c31 = new Cohort()
            {
                CohortName = "Day Cohort 31"
            };
            var c32 = new Cohort()
            {
                CohortName = "Day Cohort 32"
            };
            var c33 = new Cohort()
            {
                CohortName = "Day Cohort 33"
            };

            var adam = new Instructor
            {
                FirstName   = "Adam",
                LastName    = "Sheaffer",
                SlackHandle = "Teachers Pet",
                Specialty   = "Hacking"
            };
            var brian = new Instructor
            {
                FirstName   = "Brian",
                LastName    = "Highfive",
                SlackHandle = "Rocker",
                Specialty   = "High Five"
            };
            var jisie = new Instructor
            {
                FirstName   = "Jisie",
                LastName    = "David",
                SlackHandle = "Bigboss",
                Specialty   = "Hacking"
            };
            var bill = new Instructor
            {
                FirstName   = "Bill",
                LastName    = "Bob",
                SlackHandle = "Red neck",
                Specialty   = "Shooting guns"
            };

            c32.addInstructorToCohort(brian);
            c32.addInstructorToCohort(bill);
            c32.addInstructorToCohort(jisie);

            var jake = new Student
            {
                FirstName   = "Jake",
                LastName    = "Smith",
                SlackHandle = "JSmith"
            };

            var logan = new Student
            {
                FirstName   = "Logan",
                LastName    = "Baxter",
                SlackHandle = "Baxter"
            };

            var dek = new Student
            {
                FirstName   = "Dek",
                LastName    = "America",
                SlackHandle = "DekYea"
            };

            c32.addStudentToCohort(dek);
            c32.addStudentToCohort(logan);
            c32.addStudentToCohort(jake);

            jisie.AssignExercise(logan, studentExercise);
            jisie.AssignExercise(logan, jsExercise);
            adam.AssignExercise(dek, studentExercise);
            adam.AssignExercise(dek, jsExercise);
            brian.AssignExercise(jake, studentExercise);
            brian.AssignExercise(jake, jsExercise);

            var AllStudents = new List <Student>();

            {
                AllStudents.Add(logan);
                AllStudents.Add(dek);
                AllStudents.Add(jake);
            };

            var AllInstructors = new List <Instructor>();

            {
                AllInstructors.Add(adam);
                AllInstructors.Add(brian);
                AllInstructors.Add(jisie);
            };

            var AllExercises = new List <Exercise>();

            {
                AllExercises.Add(jsExercise);
                AllExercises.Add(journal);
                AllExercises.Add(studentExercise);
                AllExercises.Add(sqlExercise);
            };

            var AllCohorts = new List <Cohort>();

            {
                AllCohorts.Add(c30);
                AllCohorts.Add(c31);
                AllCohorts.Add(c32);
                AllCohorts.Add(c33);
            };

            List <Exercise> JSExercise = (from exercise in AllExercises
                                          where exercise.Language == "JavaScript"
                                          select exercise).ToList();

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

            List <Student> studentsInChorty = (from Student in AllStudents
                                               where Student.cohort)
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // instantiate cohorts
            Cohort dayCohort40 = new Cohort("Day Cohort 40");
            Cohort dayCohort37 = new Cohort("Day Cohort 37");
            Cohort dayCohort36 = new Cohort("Day Cohort 36");

            // instantiate exercises
            Exercise nutshell = new Exercise("Nutshell", "React");
            Exercise tribute  = new Exercise("Celebrity Tribute", "HTML");
            Exercise journal  = new Exercise("Daily Journal", "JavaScript");
            Exercise bangazon = new Exercise("Bangazon", "Python/Django");

            // instantiate students
            Student john   = new Student("John", "Long", "JohnALong", "c36");
            Student holden = new Student("Holden", "Parker", "HoldenDev", "c37");
            Student guy    = new Student("Guy", "Cherkesky", "@Guy", "c40");
            Student trey   = new Student("Trey", "Suitor", "@TreySuitor", "c36");
            Student nicole = new Student("Nicole", "Noname", "@nicole", "c40");

            Instructor joe    = new Instructor("Joe", "Shepherd", "@JoeShep", "c36", "Dad jokes");
            Instructor jisie  = new Instructor("Jisie", "David", "JisieTheSith", "c40", "Sith Lord");
            Instructor brenda = new Instructor("Brenda", "Long", "@BellsMom", "c37", "Front End");

            dayCohort36.AddStudent(john);
            dayCohort36.AddStudent(trey);
            dayCohort37.AddStudent(holden);
            dayCohort40.AddStudent(guy);
            dayCohort40.AddStudent(nicole);

            dayCohort36.AddInstructor(joe);
            dayCohort37.AddInstructor(brenda);
            dayCohort40.AddInstructor(jisie);

            joe.AddExercise(tribute, john);
            joe.AddExercise(bangazon, john);
            joe.AddExercise(nutshell, john);
            joe.AddExercise(journal, trey);
            joe.AddExercise(tribute, trey);
            brenda.AddExercise(journal, holden);
            brenda.AddExercise(nutshell, holden);
            jisie.AddExercise(tribute, guy);
            jisie.AddExercise(bangazon, guy);

            List <Student> students = new List <Student>()
            {
                john,
                holden,
                guy,
                trey,
                nicole
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                bangazon,
                nutshell,
                journal,
                tribute
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                dayCohort36,
                dayCohort37,
                dayCohort40
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                joe,
                brenda,
                jisie
            };

            // foreach (Exercise exercise in john.Exercises)
            // {
            //     Console.WriteLine($"{john.FirstName} {john.LastName} has been assigned {exercise.Name}");
            // }

            var jsExercises = exercises.Where(exercise => exercise.Language == "JavaScript");

            foreach (var exercise in jsExercises)
            {
                Console.WriteLine($"{exercise.Name} is built using {exercise.Language}");
            }

            var c36Students = students.Where(student => student.Cohort == "c36");

            foreach (var student in c36Students)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName} is in {student.Cohort}");
            }

            var c37Instructors = instructors.Where(instructor => instructor.Cohort == "c37");

            foreach (var instructor in c37Instructors)
            {
                Console.WriteLine($"{instructor.FirstName} {instructor.LastName} is teaching {instructor.Cohort}");
            }

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

            Console.WriteLine("Students by last name");
            foreach (var student in studentsLastName)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

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

            foreach (var student in studentsNotWorking)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName} has zero exercises assigned.");
            }

            var numExercises = 0;

            foreach (var student in students)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName} is working on {student.Exercises.Count()} exercises.");
                if (student.Exercises.Count() >= numExercises)
                {
                    numExercises = student.Exercises.Count();
                    Console.WriteLine($"{student.FirstName} {student.LastName} is working on {numExercises} exercises, and that is the most");
                }
            }

            foreach (var cohort in cohorts)
            {
                Console.WriteLine($"There are {cohort.Students.Count()} students in {cohort.Name}");
            }
        }
コード例 #3
0
 // this ia a method, a method to assign an exercise to a student
 public void AssignExercises(Exercise exercise, Student student)
 {
     student.ExerciseList.Add(exercise);
 }
コード例 #4
0
        static void Main(string[] args)
        {
            /*
             *  1. Create 4, or more, exercises.
             *  2. Create 3, or more, cohorts.
             *  3. Create 4, or more, students and assign them to one of the cohorts.
             *  4. Create 3, or more, instructors and assign them to one of the cohorts.
             *  5. Have each instructor assign 2 exercises to each of the students.
             */

            // 1. Create 4, or more, exercises.
            Exercise ex1 = new Exercise("daily journal", "javascript");
            Exercise ex2 = new Exercise("urban planner", "c#");
            Exercise ex3 = new Exercise("kennel", "reactjs");
            Exercise ex4 = new Exercise("kandy korner", "reactjs");

            // 2. Create 3, or more, cohorts.
            Cohort c30 = new Cohort("c30");
            Cohort c31 = new Cohort("c31");
            Cohort c32 = new Cohort("c32");
            Cohort c33 = new Cohort("c33");

            // set the student list to be added here

            //3. Create 4, or more, students and assign them to one of the cohorts.
            Student Rose     = new Student("Rose", "Witzosky", "Rose", c30);
            Student Jonathon = new Student("Jonathon", "Schaffer", "Jon", c30);
            Student Alex     = new Student("Alex", "Thacker", "Alex", c31);
            Student Billy    = new Student("Billy", "Mathison", "Billy", c31);
            Student Meag     = new Student("Meag", "Mueller", "Meag", c32);
            Student Stephen  = new Student("Stephen", "Senft", "Stephen", c32);
            Student Chris    = new Student("Chris", "Morgan", "Chris", c33);
            Student Sam      = new Student("Sam", "Britt", "Sam", c33);

            c30.StudentsList.Add(Rose);
            c30.StudentsList.Add(Jonathon);
            c31.StudentsList.Add(Alex);
            c31.StudentsList.Add(Billy);
            c32.StudentsList.Add(Meag);
            c32.StudentsList.Add(Stephen);
            c33.StudentsList.Add(Chris);
            c33.StudentsList.Add(Sam);

            //4. Create 3, or more, instructors and assign them to one of the cohorts.

            Instructor Jisie   = new Instructor("Jisie", "Davis", "Jisie", c30, "dancing");
            Instructor Kristen = new Instructor("Kristen", "Norris", "Kristen", c31, "baking");
            Instructor Andy    = new Instructor("Andy", "Collins", "Andy", c31, "dancing");
            Instructor Leah    = new Instructor("Leah", "Gwin", "Leah", c30, "programming");
            Instructor Brenda  = new Instructor("Brenda", "Long", "Brenda", c32, "designing");
            Instructor Bryan   = new Instructor("Bryan", "Nilsen", "Bryan", c32, "basketball");
            Instructor Steve   = new Instructor("Steve", "Brownlee", "Steve", c33, "talking");
            Instructor Maddie  = new Instructor("Maddie", "Peper", "Madi", c33, "pre-work");

            c30.InstructorsList.Add(Jisie);
            c30.InstructorsList.Add(Leah);
            c31.InstructorsList.Add(Kristen);
            c31.InstructorsList.Add(Andy);
            c32.InstructorsList.Add(Brenda);
            c32.InstructorsList.Add(Bryan);
            c33.InstructorsList.Add(Steve);
            c33.InstructorsList.Add(Maddie);

            //Have each instructor assign 2 exercises to each of the students in their cohort
            // c30
            Jisie.AssignEx(Rose, ex1);
            Jisie.AssignEx(Rose, ex2);
            Jisie.AssignEx(Jonathon, ex3);
            Jisie.AssignEx(Jonathon, ex4);
            Leah.AssignEx(Rose, ex3);
            Leah.AssignEx(Rose, ex4);
            Leah.AssignEx(Jonathon, ex1);
            Leah.AssignEx(Jonathon, ex2);

            //31
            Kristen.AssignEx(Billy, ex3);
            Kristen.AssignEx(Billy, ex4);
            Kristen.AssignEx(Alex, ex3);
            Kristen.AssignEx(Alex, ex4);
            Andy.AssignEx(Alex, ex1);
            Andy.AssignEx(Alex, ex2);
            Andy.AssignEx(Billy, ex1);
            Andy.AssignEx(Billy, ex2);

            //32
            Bryan.AssignEx(Meag, ex1);
            Bryan.AssignEx(Meag, ex2);
            Bryan.AssignEx(Stephen, ex1);
            Bryan.AssignEx(Stephen, ex2);
            Brenda.AssignEx(Meag, ex3);
            Brenda.AssignEx(Meag, ex4);
            Brenda.AssignEx(Stephen, ex3);
            Brenda.AssignEx(Stephen, ex4);


            //33
            Maddie.AssignEx(Sam, ex1);
            Maddie.AssignEx(Sam, ex2);
            Maddie.AssignEx(Chris, ex1);
            Maddie.AssignEx(Chris, ex2);
            Steve.AssignEx(Chris, ex3);
            Steve.AssignEx(Chris, ex4);
            Steve.AssignEx(Sam, ex3);
            Steve.AssignEx(Sam, ex4);

            // C H A L L E N G E
            List <Student> students = new List <Student>
            {
                Rose, Jonathon, Meag, Stephen, Sam, Billy, Chris, Alex
            };

            List <Exercise> exercises = new List <Exercise>
            {
                ex1, ex2, ex3, ex4
            };

            //Generate a report that displays which students are working on which exercises.
            foreach (Student student in students)
            {
                Console.Write($"{student.FirstName} {student.LastName} is working on the following exercises: ");
                foreach (Exercise studentEx in student.StudentExerciseList)
                {
                    Console.Write($"{studentEx.Name} ");
                }
                Console.WriteLine("");
            }
        }
コード例 #5
0
 // METHODS
 public void AssignExercise(Student student, Exercise exercise)
 {
     student.StudentExercises.Add(exercise);
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: aborgra/StudentExercises
        static void Main(string[] args)
        {
            Exercise classPractice = new Exercise("Class Practice", "C#");
            Exercise semicolons    = new Exercise("Semicolons", "JS");
            Exercise constructors  = new Exercise("Constructor Practice", "C#");
            Exercise functions     = new Exercise("Functions", "JS");

            Cohort cohort35 = new Cohort("E35");
            Cohort cohort36 = new Cohort("D36");
            Cohort cohort37 = new Cohort("D37");

            Student james   = new Student("James", "Nitz", "agrant", "E35");
            Student kevin   = new Student("Kevin", "Penny", "kpenny", "D36");
            Student willy   = new Student("Willy", "Metcalf", "wmetcalf", "D37");
            Student audrey  = new Student("Audrey", "Borgra", "aborgra", "D37");
            Student slacker = new Student("Slacker", "McGee", "slacker", "D37");

            cohort35.AddStudent(james);
            cohort36.AddStudent(kevin);
            cohort37.AddStudent(willy);
            cohort37.AddStudent(audrey);
            cohort37.AddStudent(slacker);

            Instructor steve = new Instructor("Steve", "Brownlee", "Chortlehoort", "D37");
            Instructor adam  = new Instructor("Adam", "Schaeffer", "aschaeffer", "D36");
            Instructor mo    = new Instructor("Mo", "Silva", "msilva", "E35");

            cohort37.AddInstuctor(steve);
            cohort36.AddInstuctor(adam);
            cohort35.AddInstuctor(mo);

            steve.AssignExercise(audrey, classPractice);
            steve.AssignExercise(audrey, semicolons);
            steve.AssignExercise(willy, classPractice);
            steve.AssignExercise(willy, semicolons);
            adam.AssignExercise(kevin, constructors);
            adam.AssignExercise(kevin, semicolons);
            mo.AssignExercise(james, functions);
            mo.AssignExercise(james, classPractice);
            mo.AssignExercise(james, semicolons);
            mo.AssignExercise(james, constructors);
            steve.AssignExercise(audrey, functions);

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

            students.Add(james);
            students.Add(willy);
            students.Add(kevin);
            students.Add(audrey);
            students.Add(slacker);

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

            exercises.Add(classPractice);
            exercises.Add(functions);
            exercises.Add(semicolons);
            exercises.Add(constructors);

            List <Instructor> instructors = new List <Instructor> {
                steve,
                adam,
                mo
            };

            List <Cohort> cohorts = new List <Cohort> {
                cohort35,
                cohort36,
                cohort37
            };

            foreach (Exercise exercise in exercises)
            {
                Console.WriteLine($"{exercise.Name}:");

                foreach (Student student in students)
                {
                    foreach (Exercise studentExercise in student.Exercises)
                    {
                        if (exercise.Name == studentExercise.Name)
                        {
                            Console.WriteLine($"{student.FirstName} {student.LastName}");
                        }
                    }
                }
                Console.WriteLine($"--------------------");
            }

            var filteredJSExercises = exercises.Where(exercise => exercise.Language == "JS");

            Console.WriteLine($"JavaScript exercises:");

            foreach (var exercise in filteredJSExercises)
            {
                Console.WriteLine($"{exercise.Name}");
            }
            Console.WriteLine($"________________________");

            var cohort37Students = students.Where(student => student.Cohort == "D37");

            Console.WriteLine($"Students in cohort 37:");

            foreach (var student in cohort37Students)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }
            Console.WriteLine($"________________________");

            var cohort37Instructors = instructors.Where(instructor => instructor.Cohort == "D37");

            Console.WriteLine($"Instructors in cohort 37:");

            foreach (var instructor in cohort37Instructors)
            {
                Console.WriteLine($"{instructor.FirstName} {instructor.LastName}");
            }
            Console.WriteLine($"________________________");

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

            Console.WriteLine($"Students sorted by last name:");

            foreach (var student in sortedStudentNames)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }
            Console.WriteLine($"________________________");

            var studentsWithoutExercises = students.Where(student => { return(student.Exercises.Count == 0 || student.Exercises == null); });

            Console.WriteLine($"Students without exercises:");

            foreach (var student in studentsWithoutExercises)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }
            Console.WriteLine($"________________________");

            var orderedStudentsByExercisesCount = students.OrderByDescending(student => {
                return(student.Exercises.Count());
            }).FirstOrDefault();

            Console.WriteLine($"Student with the most exercises:");

            Console.WriteLine($"{orderedStudentsByExercisesCount.FirstName} {orderedStudentsByExercisesCount.LastName}");
            Console.WriteLine($"________________________");

            // Easier for printing to the console
            var groups = students.GroupBy(student => student.Cohort);

            Console.WriteLine("Students in each cohort:");
            foreach (var group in groups)
            {
                Console.WriteLine($"{group.Count()} in {group.Key}");
            }

            // Better for storing info to be used later
            var studentsPerCohort = students.GroupBy(student => student.Cohort).Select(group => {
                return(new CohortReport {
                    StudentCount = group.Count(),
                    Name = group.Key
                });
            });

            Console.WriteLine("Students in each cohort:");
            foreach (var group in studentsPerCohort)
            {
                Console.WriteLine($"{group.Name} has {group.StudentCount}");
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Exercise MartinsAquarium = new Exercise()
            {
                name = "MartinsAquarium",
                language = "JavaScript"
            };

            Exercise CongressionalRep = new Exercise()
            {
                name = "Congressional Representative",
                language = "HTML"
            };

            Exercise Nutshell = new Exercise()
            {
                name = "Nutshell",
                language = "React"
            };

            Exercise Buildings = new Exercise()
            {
                name = "Buildings",
                language = "C#"
            };

            Cohort C35 = new Cohort()
            {
                name = "Cohort 35"
            };

            Cohort C36 = new Cohort()
            {
                name = "Cohort 36"
            };

            Cohort C37 = new Cohort()
            {
                name = "Cohort 37"
            };

            Student Sage = new Student()
            {
                FirstName = "Sage",
                LastName = "Foo",
                SlackHandle = "SageFoo",
                Cohort = "Cohort 35"
            };

            Student RyanB = new Student()
            {
                FirstName = "Ryan",
                LastName = "Bishop",
                SlackHandle = "RyanB",
                Cohort = "Cohort 36"
            };

            Student JohnG = new Student()
            {
                FirstName = "John",
                LastName = "Gilliam",
                SlackHandle = "JG",
                Cohort = "Cohort 37"
            };

            Student SpencerT = new Student()
            {
                FirstName = "Spencer",
                LastName = "Truett",
                SlackHandle = "ST",
                Cohort = "Cohort 37"
            };

            Student SlackerStudent = new Student()
            {
                FirstName = "Slacker",
                LastName = "McGee",
                SlackHandle = "SM",
                Cohort = "Cohort 37"
            };

            C35.AddStudent(Sage);
            C36.AddStudent(RyanB);
            C37.AddStudent(JohnG);
            C37.AddStudent(SpencerT);

            Instructor SteveB = new Instructor()
            {
                FirstName = "Steve",
                LastName = "Brownlee",
                SlackHandle = "choortlehort",
                Specialty = "Dad Jokes",
                Cohort = "Cohort 35"
            };

            Instructor AdamS = new Instructor()
            {
                FirstName = "Adam",
                LastName = "Sheaffer",
                SlackHandle = "AdamS",
                Specialty = "var",
                Cohort = "Cohort 36"
            };

            Instructor Leah = new Instructor()
            {
                FirstName = "Leah",
                LastName = "Hoefling",
                SlackHandle = "LemurLeah",
                Specialty = "Traveling",
                Cohort = "Cohort 37"
            };

            C35.AddInstructor(SteveB);
            C36.AddInstructor(AdamS);
            C37.AddInstructor(Leah);

            SteveB.assignExercise(Sage, MartinsAquarium);
            SteveB.assignExercise(Sage, CongressionalRep);
            SteveB.assignExercise(RyanB, Nutshell);
            SteveB.assignExercise(RyanB, Buildings);
            SteveB.assignExercise(JohnG, MartinsAquarium);
            SteveB.assignExercise(JohnG, Nutshell);
            SteveB.assignExercise(SpencerT, CongressionalRep);
            SteveB.assignExercise(SpencerT, Nutshell);
            SteveB.assignExercise(SpencerT, MartinsAquarium);

            AdamS.assignExercise(Sage, Nutshell);
            AdamS.assignExercise(Sage, Buildings);
            AdamS.assignExercise(RyanB, MartinsAquarium);
            AdamS.assignExercise(RyanB, CongressionalRep);
            AdamS.assignExercise(JohnG, Buildings);
            AdamS.assignExercise(JohnG, CongressionalRep);
            AdamS.assignExercise(SpencerT, Buildings);
            AdamS.assignExercise(SpencerT, MartinsAquarium);

            Leah.assignExercise(Sage, Nutshell);
            Leah.assignExercise(Sage, MartinsAquarium);
            Leah.assignExercise(RyanB, MartinsAquarium);
            Leah.assignExercise(RyanB, Buildings);
            Leah.assignExercise(JohnG, Nutshell);
            Leah.assignExercise(JohnG, Buildings);
            Leah.assignExercise(SpencerT, CongressionalRep);
            Leah.assignExercise(SpencerT, MartinsAquarium);

            List<Student> students = new List<Student>();
            students.Add(Sage);
            students.Add(RyanB);
            students.Add(JohnG);
            students.Add(SpencerT);
            students.Add(SlackerStudent);

            List<Exercise> exercises = new List<Exercise>();
            exercises.Add(MartinsAquarium);
            exercises.Add(CongressionalRep);
            exercises.Add(Buildings);
            exercises.Add(Nutshell);

            List<Instructor> instructors = new List<Instructor>();
            instructors.Add(SteveB);
            instructors.Add(AdamS);
            instructors.Add(Leah);

            List<Cohort> cohorts = new List<Cohort>();
            cohorts.Add(C35);
            cohorts.Add(C36);
            cohorts.Add(C37);

            // foreach (Exercise exercise in exercises)
            // {
            //     Console.WriteLine($"{exercise.name}:");

            //     foreach (Student student in students)
            //     {
            //         foreach (Exercise studentExercise in student.Exercises)
            //         {
            //             if (exercise.name == studentExercise.name)
            //             {
            //                 Console.WriteLine($"{student.FirstName} {student.LastName}");

            //             }

            //         }

            //     }
            //     Console.WriteLine($"--------------------");

            // }

            // List exercises for the JavaScript language by using the Where() LINQ method.

            // IEnumerable<Exercise> JavaScriptExercises =
            // from exercise in exercises
            // where exercise.language == "JavaScript"
            // select exercise;

            // foreach (Exercise exercise in JavaScriptExercises)
            // {
            //     Console.WriteLine(exercise.name);
            // }

            // IEnumerable<Student> StudentsInCohort37 =
            // from student in students
            // where student.Cohort == "Cohort 37"
            // select student;

            // foreach (Student student in StudentsInCohort37)
            // {
            //     Console.WriteLine(student.FirstName);
            // }

            // IEnumerable<Instructor> InstructorsInCohort37 =
            // from instructor in instructors
            // where instructor.Cohort == "Cohort 37"
            // select instructor;

            // foreach (Instructor instructor in InstructorsInCohort37)
            // {
            //     Console.WriteLine(instructor.FirstName);
            // };

            // IEnumerable<Student> StudentsByLastName =
            // from student in students
            // orderby student.LastName descending
            // select student;

            // foreach (Student student in StudentsByLastName)
            // {
            //     Console.WriteLine(student.LastName);
            // }

            // IEnumerable<Student> StudentsWithoutExercises =
            // from student in students
            // where student.Exercises.Count == 0
            // select student;

            // foreach (Student student in StudentsWithoutExercises)
            // {
            //     Console.WriteLine(student.FirstName);
            // }

            IEnumerable<Student> StudentWithMostExercises =
            from student in students
            orderby student.Exercises.Count() descending
            select.FirstOrDefault() student;

            var overachiever = StudentWithMostExercises.FirstOrDefault();

            Console.WriteLine(overachiever.FirstName);

            // IEnumerable<CohortReport> studentsPerCohort = students
            // .GroupBy(student => student.Cohort)
            // .Select(Group =>
            // {
            //     return new CohortReport
            //     {
            //         StudentCount = Group.Count(),
            //         CohortName = Group.Key
            //     };
            // });

            // foreach (CohortReport cohort in studentsPerCohort)
            // {
            //     Console.WriteLine($"{cohort.CohortName} has {cohort.StudentCount}");
            // }
        }
コード例 #8
0
        static void Main(string[] args)
        {
            // Exercise list with 4 exercises added to the list
            {
                Exercise firstEx = new Exercise();
                firstEx.ExerciseName     = "Basic Website";
                firstEx.ExerciseLanguage = "HTML";

                Exercise secondEx = new Exercise();
                secondEx.ExerciseName     = "Website with Style";
                secondEx.ExerciseLanguage = "CSS";

                Exercise thirdEx = new Exercise();
                thirdEx.ExerciseName     = "Nutshell with JS";
                thirdEx.ExerciseLanguage = "Javascript";

                Exercise fourthEx = new Exercise();
                fourthEx.ExerciseName     = "Nutshell with React";
                fourthEx.ExerciseLanguage = "React";

                List <Exercise> exercises = new List <Exercise>()
                {
                    firstEx,
                    secondEx,
                    thirdEx,
                    fourthEx
                };

                // List of Cohorts

                Cohort cohort33 = new Cohort("Cohort 33");
                Cohort cohort34 = new Cohort("Cohort 34");
                Cohort cohort35 = new Cohort("Cohort 35");

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

                // List of Students

                Student student1 = new Student();
                student1.FirstName = " Dylan";
                student1.LastName  = "Pickle";
                student1.Slack     = "dylp";

                Student student2 = new Student();
                student2.FirstName = "Shirish";
                student2.LastName  = "Shrestha";
                student2.Slack     = "shirishshrestha";

                Student student3 = new Student();
                student3.FirstName = "Heidi";
                student3.LastName  = "Smith";
                student3.Slack     = "heidismith";

                Student student4 = new Student();
                student4.FirstName = "Lauren";
                student4.LastName  = "Maxwell";
                student4.Slack     = "laureneliza";

                Student student5 = new Student();
                student5.FirstName = "Phil";
                student5.LastName  = "Griswold";
                student5.Slack     = "phil";

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

                // Add students to Cohorts
                cohort33.Students.Add(student1);
                cohort34.Students.Add(student2);
                cohort35.Students.Add(student3);
                cohort35.Students.Add(student4);
                cohort35.Students.Add(student5);

                // List of Instructors

                Instructor teacher1 = new Instructor();
                teacher1.FirstName  = "Madi";
                teacher1.LastName   = "Peper";
                teacher1.Slack      = "madipeper";
                teacher1.Speciality = "Knows how to explain things";

                Instructor teacher2 = new Instructor();
                teacher2.FirstName  = "Mo";
                teacher2.LastName   = "Silvera";
                teacher2.Slack      = "mo";
                teacher2.Speciality = "joking around";

                Instructor teacher3 = new Instructor();
                teacher3.FirstName  = "Adam";
                teacher3.LastName   = "Sheaffer";
                teacher3.Slack      = "adamsheaf";
                teacher3.Speciality = "Makes sure everyone is understanding";


                List <Instructor> teachers = new List <Instructor>()
                {
                    teacher1,
                    teacher2,
                    teacher3
                };


                // Assigning Instructors to a cohort
                cohort33.Instructors.Add(teacher1);
                cohort34.Instructors.Add(teacher2);
                cohort35.Instructors.Add(teacher3);

                // Assigning exercises to each of the students
                teacher1.assignStudentExercise(student4, fourthEx);
                teacher2.assignStudentExercise(student3, thirdEx);
                teacher3.assignStudentExercise(student2, secondEx);
                teacher3.assignStudentExercise(student1, firstEx);
                teacher3.assignStudentExercise(student4, thirdEx);
                teacher3.assignStudentExercise(student4, firstEx);


                // Display which students are working on which exercises
                foreach (Student student in students)
                {
                    foreach (Exercise exercise in student.Exercises)
                    {
                        Console.WriteLine($"{student.FirstName} {student.LastName}  is working on {exercise.ExerciseName}");
                    }
                }
                Console.WriteLine("=============================");
                //Student Exercises Part 2

                // 1.) Display Exercises done in Javascript
                var jsExercises = exercises.Where(ex => ex.ExerciseLanguage == "Javascript").ToList();
                Console.WriteLine("List of Exercises in Javascript");
                foreach (Exercise exercise in jsExercises)
                {
                    Console.WriteLine($"{exercise.ExerciseName}");
                }

                // 2.)Display Students in Cohort 35
                var studentsIn35 = cohorts.Where(co => co.CohortName == "Cohort 35").SelectMany(c => c.Students)
                                   .Distinct();
                Console.WriteLine("Students in Cohort 35");
                foreach (var student in studentsIn35)
                {
                    Console.WriteLine($"{student.FirstName}");
                }

                // 3.)Display Teachers in Cohort 33
                var teachersIn33 = cohorts.Where(co => co.CohortName == "Cohort 33").SelectMany(c => c.Instructors)
                                   .Distinct();
                Console.WriteLine("Teachers in Cohort 35");
                foreach (var teacher in teachersIn33)
                {
                    Console.WriteLine($"{teacher.FirstName}");
                }

                Console.WriteLine("====================");

                //4.) Sort students by their last name
                var studentOrder = students.OrderBy(name => name.LastName).ToList();

                foreach (var student in studentOrder)
                {
                    Console.WriteLine($"{student.LastName}");
                }
                Console.WriteLine("====================");

                // 5.)Display any students that are NOT assigned an exercise
                var studentsWOEx = students.Where(ex => ex.Exercises.Count == 0).ToList();

                foreach (var stud in studentsWOEx)
                {
                    Console.WriteLine($"{stud.FirstName}");
                }
                Console.WriteLine("====================");

                // 6.)Display the Student working on the most exercises
                var studentWMost = students.Select(s => new
                {
                    firstName      = s.FirstName,
                    numOfExercises = s.Exercises.Count()
                }).OrderByDescending(s => s.numOfExercises).FirstOrDefault();

                Console.WriteLine($"{studentWMost.firstName} has {studentWMost.numOfExercises}");

                Console.WriteLine("====================");

                // 7.)Display the number of students in each cohort
                var numStudentsInCohorts = cohorts.Select(c => new
                {
                    cohortName    = c.CohortName,
                    numOfStudents = c.Students.Count()
                }).ToList();

                foreach (var student in numStudentsInCohorts)
                {
                    Console.WriteLine($"{student.cohortName} has {student.numOfStudents} students.");
                }
            }
        }
コード例 #9
0
 public void addExercise(Exercise exercise)
 {
     _exercises.Add(exercise);
 }
コード例 #10
0
        static void Main(string[] args)
        {
            // Create Exercises
            Exercise celebrityTribute = new Exercise()
            {
                Name = "Celebrity Tribute",
                ProgrammingLanguage = "HTML and CSS"
            };

            Exercise chickenMonkey = new Exercise()
            {
                Name = "Chicken Monkey",
                ProgrammingLanguage = "JavaScript"
            };

            Exercise kneelDiamonds = new Exercise()
            {
                Name = "Kneel Diamonds",
                ProgrammingLanguage = "JavaScript"
            };

            Exercise planYourHeist = new Exercise()
            {
                Name = "Plan Your Heist",
                ProgrammingLanguage = "C#"
            };

            // Create Cohorts
            Cohort evening09 = new Cohort()
            {
                Name = "Evening Cohort 09"
            };
            Cohort day34 = new Cohort()
            {
                Name = "Day Cohort 34"
            };
            Cohort day35 = new Cohort()
            {
                Name = "Day Cohort 35"
            };

            // Create Students
            Student angela = new Student()
            {
                FirstName   = "Angela",
                LastName    = "Anderson",
                SlackHandle = "@angela",
                Cohort      = evening09
            };

            Student blake = new Student()
            {
                FirstName   = "Blake",
                LastName    = "Buford",
                SlackHandle = "@blake",
                Cohort      = day34
            };

            Student chris = new Student()
            {
                FirstName   = "Chris",
                LastName    = "Collinsworth",
                SlackHandle = "@chris",
                Cohort      = day34
            };

            Student jason = new Student()
            {
                FirstName   = "Jason",
                LastName    = "Jones",
                SlackHandle = "@jason",
                Cohort      = day35
            };

            Student zack = new Student()
            {
                FirstName   = "Zack",
                LastName    = "Zelson",
                SlackHandle = "@zack",
                Cohort      = day34
            };

            evening09.students.Add(angela);
            day34.students.Add(blake);
            day34.students.Add(chris);
            day35.students.Add(jason);
            day34.students.Add(zack);

            // Create Instructors
            Instructor andy = new Instructor()
            {
                FirstName   = "Andy",
                LastName    = "Collins",
                SlackHandle = "@andy",
                Specialty   = "Pointing",
                Cohort      = evening09
            };

            Instructor bryan = new Instructor()
            {
                FirstName   = "Bryan",
                LastName    = "Nilsen",
                SlackHandle = "@bry-5",
                Specialty   = "High-fiving",
                Cohort      = day34
            };

            Instructor jenna = new Instructor()
            {
                FirstName   = "Jenna",
                LastName    = "Solis",
                SlackHandle = "@jenna",
                Specialty   = "Stuffed animal conveyor belts",
                Cohort      = day35
            };

            evening09.instructors.Add(andy);
            day34.instructors.Add(bryan);
            day35.instructors.Add(jenna);

            andy.AssignExercise(angela, celebrityTribute);
            bryan.AssignExercise(blake, celebrityTribute);
            bryan.AssignExercise(blake, chickenMonkey);
            andy.AssignExercise(blake, kneelDiamonds);
            bryan.AssignExercise(jason, celebrityTribute);
            jenna.AssignExercise(jason, chickenMonkey);
            andy.AssignExercise(chris, celebrityTribute);
            andy.AssignExercise(chris, chickenMonkey);
            jenna.AssignExercise(chris, kneelDiamonds);
            jenna.AssignExercise(chris, planYourHeist);

            // Generate a report that displays which students are working on which exercises.
            // Clarification: Iterate over all exercises and then only print the students who are assigned to that exercise.

            List <Student> students = new List <Student>()
            {
                zack, angela, blake, chris, jason
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                celebrityTribute, chickenMonkey, kneelDiamonds, planYourHeist
            };

            foreach (Exercise exercise in exercises)
            {
                Console.WriteLine();
                Console.WriteLine("-------------------------");
                Console.WriteLine($"Exercise: {exercise.Name}");
                Console.WriteLine("-------------------------");

                foreach (Student student in students)
                {
                    if (student.exercises.Contains(exercise))
                    {
                        Console.WriteLine($"{student.FirstName} {student.LastName}");
                    }
                }
            }

            // Student Exercises: Part 2
            List <Instructor> instructors = new List <Instructor>()
            {
                andy, bryan, jenna
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                evening09, day34, day35
            };

            // List exercises for the JavaScript language by using the Where() LINQ method.
            List <Exercise> javaScriptExercises = exercises.Where(exercise => exercise.ProgrammingLanguage == "JavaScript").ToList();

            // List students in a particular cohort by using the Where() LINQ method.
            List <Student> cohort34Students = students.Where(student => student.Cohort == day34).ToList();

            // List instructors in a particular cohort by using the Where() LINQ method.
            List <Instructor> cohort34Instructors = instructors.Where(instructor => instructor.Cohort == day34).ToList();

            // Sort the students by their last name.
            var studentsSortedABC = students.OrderBy(student => student.LastName);

            // Display any students that aren't working on any exercises (Make sure one of your student instances don't have any exercises. Create a new student if you need to.)
            var studentsWithoutExercises = students.Where(student => student.exercises.Count == 0);

            // Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            var studentWithMostExercises = students.OrderByDescending(student => student.exercises.Count()).First();

            // How many students in each cohort?
            var studentCount = students.GroupBy(
                student => student.Cohort,
                (key, value) => new
            {
                StudentName  = key,
                StudentCount = value.Count()
            });
        }
コード例 #11
0
 public void assignStudents(Student student, Exercise exercise)
 {
     student.exercises.Add(exercise);
 }
コード例 #12
0
        public void AddExerciseToStudent(Exercise exercise)

        {
            StudentCollectionOfExercises.Add(exercise);
        }
コード例 #13
0
        static void Main(string[] args)
        {
            // Once you have defined all of your custom types, go to your Main() method in Program.cs and implement the following logic.

            // Create 4, or more, exercises.
            // Create 3, or more, cohorts.
            // Create 4, or more, students and assign them to one of the cohorts.
            // Create 3, or more, instructors and assign them to one of the cohorts.
            // Have each instructor assign 2 exercises to each of the students.

            //create the exercises
            Exercise nutshell           = new Exercise("Nutshell React", "JavaScript");
            Exercise celebrityTribute   = new Exercise("Celebrity Tribute", "HTML");
            Exercise chickenMonkey      = new Exercise("Chicken Monkey", "JavaScript");
            Exercise welcomeToNashville = new Exercise("Welcome to Nashville", "JavaScript");
            Exercise CityPlanning       = new Exercise("City Planning", "C#");

            //cohorts

            Cohort cohort34  = new Cohort("Full-Time Cohort 34");
            Cohort cohort33  = new Cohort("Full-Time Cohort 33");
            Cohort evening15 = new Cohort("Evening Cohort 15");

            //students

            Student brian   = new Student("Brian", "Wilson", "Brian Wilson", cohort34);
            Student curtis  = new Student("Curtis", "Crutchfield", "Curtis Crutchfield", cohort34);
            Student shelley = new Student("Shelley", "Thomas", "Shelley Thomas", evening15);
            Student allie   = new Student("Allie", "Patton", "Allie Patton", cohort34);
            Student john    = new Student("John", "Adams", "John Adams", cohort33);

            //assign students to cohorts

            cohort34.Students.Add(brian);
            cohort34.Students.Add(curtis);
            evening15.Students.Add(shelley);
            cohort34.Students.Add(allie);
            cohort33.Students.Add(john);

            //instructors

            Instructor steve  = new Instructor("Steve", "Brownlee", "Steve Brownlee", cohort33, "ninja skills");
            Instructor andy   = new Instructor("Andy", "Collins", "Andy Collins", cohort34, "invented csharp");
            Instructor brenda = new Instructor("Brenda", "Long", "Brenda Long", evening15, "CSS Wizard");

            //assign instructors to cohorts
            cohort34.Instructors.Add(andy);
            cohort33.Instructors.Add(steve);
            evening15.Instructors.Add(brenda);

            //assign exercises - cohort 34

            andy.SetAssignment(chickenMonkey, brian);
            andy.SetAssignment(nutshell, brian);
            andy.SetAssignment(chickenMonkey, allie);
            andy.SetAssignment(nutshell, allie);
            andy.SetAssignment(chickenMonkey, curtis);
            andy.SetAssignment(nutshell, curtis);
            brenda.SetAssignment(CityPlanning, john);
            steve.SetAssignment(nutshell, john);
            andy.SetAssignment(welcomeToNashville, john);

            //assign exercises - cohort 33

            //assign exercises - evening 15

            // Create a list of all the students
            List <Student> allTheStudents = new List <Student>()
            {
                brian, allie, curtis, shelley, john
            };

            foreach (Student student in allTheStudents)
            {
                // Console.WriteLine($"The students sorted normally: {student.FirstName} {student.LastName}");
            }

            // Create a list of all the exercises
            List <Exercise> allTheExercises = new List <Exercise>()
            {
                chickenMonkey, nutshell, welcomeToNashville, celebrityTribute
            };

            // Create a lit of all cohorts
            List <Cohort> allTheCohorts = new List <Cohort>()
            {
                cohort33, cohort34, evening15
            };

            //Create a list of all the instructors
            List <Instructor> allTheInstructors = new List <Instructor> {
                steve, andy, brenda
            };

            // Generate a report that displays which students are working on which exercises.

            //List exercises for the JavaScript language by using the Where() LINQ method.
            List <Exercise> javaScript = allTheExercises.Where(exercise => exercise.Language == "JavaScript").ToList();

            //Print out the all the exercises by that language

            foreach (Exercise exercise in javaScript)
            {
                // Console.WriteLine($"{exercise.Name}: {exercise.Language}");
            }

            // List students in a particular cohort by using the Where() LINQ method.

            List <Student> Cohort34Students = allTheStudents.Where(student => student.Cohort.Name == "Full-Time Cohort 34").ToList();

            //Loop through students to get all students from that cohort
            foreach (Student student in Cohort34Students)
            {
                // Console.WriteLine($"Student: {student.FirstName} {student.LastName}, Cohort: {student.Cohort.Name}");
            }

            //List instructors in a particular cohort by using the Where() LINQ method.

            List <Instructor> Cohort34Instructor = allTheInstructors.Where(instructor => instructor.Cohort.Name == "Full-Time Cohort 34").ToList();

            foreach (Instructor instructor in Cohort34Instructor)
            {
                // Console.WriteLine($"Instructor: {instructor.FirstName} {instructor.LastName}, Cohort: {instructor.Cohort.Name}");
            }

            //sort students by last name
            List <Student> StudentsLastNameOrder = allTheStudents.OrderBy(p => p.LastName).ThenBy(p => p.FirstName).ToList();

            foreach (Student student in StudentsLastNameOrder)
            {
                // Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            // Display any students that aren't working on any exercises (Make sure one of your student instances don't have any exercises. Create a new student if you need to.)
            List <Student> StudentsWithNoExercises = allTheStudents.Where(student => student.Exercises.Count() == 0).ToList();

            foreach (Student student in StudentsWithNoExercises)
            {
                // Console.WriteLine("Students who have not been assigned exercises:");
                // Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            //Which student is working on the most exercises? Make sure one of your students has more exercises than the others.

            List <Student> StudentsWithMostExercises = allTheStudents.OrderByDescending(student => student.Exercises.Count()).ToList();
            Student        mostExercises             = StudentsWithMostExercises[0];

            Console.WriteLine($"Student with the most exercises assigned is {mostExercises.FirstName} {mostExercises.LastName}");

            //How many students in each cohort?

            var studentsPerCohort = allTheStudents.GroupBy(student => student.Cohort,
                                                           student => student, (key, g) => new
            {
                Cohort        = key,
                NumOfStudents = g.Count()
            }
                                                           );

            foreach (var count in studentsPerCohort)
            {
                Console.WriteLine($"{count.Cohort.Name}: {count.NumOfStudents}");
            }



            //loop through the exercises to get exercise names
            foreach (Exercise exercise in allTheExercises)
            {
                // Console.WriteLine();
                // Console.WriteLine($"{exercise.Name}: ");
                // Console.WriteLine();

                //loop through students to see if their object contains exercise
                foreach (Student student in allTheStudents)
                {
                    if (student.Exercises.Contains(exercise))
                    {
                        // Console.WriteLine($"{student.FirstName} {student.LastName}");
                    }
                }
                // Console.WriteLine();
                // Console.WriteLine("--------------");
            }
        }
コード例 #14
0
        static void Main(string[] args)
        {
            // Create 4, or more, exercises.
            Exercise loops        = new Exercise("Loops", "C#");
            Exercise localStorage = new Exercise("Local Storage", "Javascript");
            Exercise modules      = new Exercise("Modularization", "Javascript");
            Exercise props        = new Exercise("Props", "React");
            // Create 3, or more, cohorts.
            Cohort day26  = new Cohort("Day Cohort 26");
            Cohort day27  = new Cohort("Day Cohort 27");
            Cohort day28  = new Cohort("Day Cohort 28");
            Cohort night8 = new Cohort("Evening Cohort 8");
            // Create 4, or more, students and assign them to one of the cohorts.
            Student taylor = new Student("Taylor", "Gulley", "taylor1", day27);
            Student mark   = new Student("Mark", "Hale", "mark1", day27);
            Student vik    = new Student("Sathvik", "Reddy", "vik1", day26);
            Student nolan  = new Student("Nolan", "Little", "nolan1", day28);
            Student jon    = new Student("Jon", "Snow", "King of the North", night8);

            day27.ListOfStudents.Add(taylor);
            day27.ListOfStudents.Add(mark);
            day26.ListOfStudents.Add(vik);
            day28.ListOfStudents.Add(nolan);
            night8.ListOfStudents.Add(jon);
            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor steve = new Instructor("Steve", "Brownlee", "coach", day27);
            Instructor meg   = new Instructor("Meg", "Ducharme", "meg", day27);
            Instructor kimmy = new Instructor("Kimmy", "Bird", "kimmy", day27);
            Instructor andy  = new Instructor("Andy", "Collins", "andy", day27);

            day27.ListOfInstructors.Add(steve);
            day27.ListOfInstructors.Add(meg);
            day27.ListOfInstructors.Add(kimmy);
            day27.ListOfInstructors.Add(andy);
            // Have each instructor assign 2 exercises to each of the students.
            steve.AssignExercise(taylor, modules);
            steve.AssignExercise(taylor, props);
            meg.AssignExercise(mark, modules);
            meg.AssignExercise(mark, loops);
            kimmy.AssignExercise(vik, props);
            kimmy.AssignExercise(vik, localStorage);
            andy.AssignExercise(nolan, localStorage);
            andy.AssignExercise(nolan, loops);
            steve.AssignExercise(taylor, props);

            List <Student> students = new List <Student>()
            {
                taylor, mark, vik, nolan, jon
            };
            List <Exercise> exercises = new List <Exercise>()
            {
                loops, localStorage, modules, props
            };

            // can reference probes and planets for this, do something like  loop over the exercises then loop over the students to match up who is working on what like Modularization : Taylor, Mark
            // foreach (Student student in students)
            // {
            //     Console.WriteLine($"{student.FirstName} {student.LastName} is working on {student.StudentExercises[0].Name} and {student.StudentExercises[1].Name}");
            // }
            foreach (Exercise exercise in exercises)
            {
                List <string> matchingExercises = new List <string>();
                foreach (Student student in students)
                {
                    if (student.StudentExercises.Contains(exercise))
                    {
                        matchingExercises.Add(student.FirstName);
                    }
                }
                // Console.WriteLine($"{exercise.ExerciseName} is assigned to: {String.Join(", ", matchingExercises)}");
            }
            // Student Exercises Part 2
            List <Instructor> instructors = new List <Instructor>()
            {
                steve, meg, kimmy, andy
            };
            List <Cohort> cohorts = new List <Cohort>()
            {
                day26, day27, day28, night8
            };
            //List exercises for the JavaScript language by using the Where() LINQ method.
            IEnumerable <Exercise> javascriptExercises = from exercise in exercises
                                                         where exercise.ExerciseLanguage == "Javascript"
                                                         select exercise;
            //List students in a particular cohort by using the Where() LINQ method.
            List <Student> cohort27Students = (from student in students
                                               where student.Cohort == day27
                                               select student).ToList();
            //List instructors in a particular cohort by using the Where() LINQ method.
            List <Instructor> cohort27Instructors = instructors.Where(i => i.Cohort == day27).ToList();
            //Sort the students by their last name.
            List <Student> sortedStudents = (from student in students
                                             orderby student.LastName
                                             select student).ToList();
            //Display any students that aren't working on any exercises (Make sure one of your student instances don't have any exercises. Create a new student if you need to.)
            List <Student> studentWithoutExercises = (from student in students
                                                      where student.StudentExercises.Count == 0
                                                      select student
                                                      ).ToList();
            // Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            var studentWithMostExercises = (from student in students
                                            select new {
                FirstName = student.FirstName,
                Exercises = student.StudentExercises.Count()
            }).OrderByDescending(s => s.Exercises)
                                           .Take(1).ToList()[0];
            // How many students in each cohort?
            // GroupBy gives you a collection of groups - each group has something that it's being grouped by (the key). The group itself is the list of all of the values of the group. Returns a collection of groups.
            // collection of groups (numberOfStudentsInEachCohort)
            // METHOD WAY
            var numberOfStudentsInEachCohort = students.GroupBy(c => c.Cohort.CohortName);

            // looks at every group of students
            foreach (var studentGroup in numberOfStudentsInEachCohort)
            {
                // key is the thing you grouped by
                // Console.WriteLine($"{studentGroup.Key} has {studentGroup.Count()} students");
            }

            // SQL/QUERY WAY
            var totalStudents = from student in students
                                group student by student.Cohort into sorted
                                select new {
                Cohort   = sorted.Key,
                Students = sorted.ToList()
            };

            foreach (var total in totalStudents)
            {
                // Console.WriteLine($"Cohort {total.Cohort.Name} has {total.Students.Count()} students");
            }

            //Using Dapper to query the database
            SqliteConnection db = DatabaseInterface.Connection;

            DatabaseInterface.CheckExerciseTable();
            DatabaseInterface.CheckInstructorsTable();
            DatabaseInterface.CheckCohortsTable();

            List <Exercise> exercisesQuery = db.Query <Exercise>(@"SELECT * FROM Exercise").ToList();

            exercisesQuery.ForEach(ex => Console.WriteLine($"{ex.ExerciseName}"));

            db.Execute($@"
            INSERT INTO Exercise (ExerciseName, ExerciseLanguage) VALUES ('DOM', 'Javascript')
            ");

            List <Exercise> javascriptExercisesQuery = db.Query <Exercise>(@"SELECT * FROM Exercise WHERE ExerciseLanguage == 'Javascript'").ToList();

            javascriptExercisesQuery.ForEach(ex => Console.WriteLine($"This is a Javascript exercise {ex.ExerciseName}"));

            List <Instructor> instructorQuery = db.Query <Instructor>(@"SELECT * FROM Instructor").ToList();

            instructorQuery.ForEach(ins => Console.WriteLine($"{ins.FirstName} {ins.LastName}"));

            List <Cohort> cohortQuery = db.Query <Cohort>(@"SELECT * FROM Cohort").ToList();

            cohortQuery.ForEach(co => Console.WriteLine($"{co.CohortName}"));
        }
コード例 #15
0
 //a method to assign an exercise to a student
 public void assignExercise(Exercise exercise, Student student)
 {
     student.Exercises.Add(exercise);
 }
コード例 #16
0
        static void Main(string[] args)
        {
// Exercises
            Exercise Gitstuff    = new Exercise("Git Stuff", "git");
            Exercise DomPractice = new Exercise("DOM Practice", "JavaScript");
            Exercise Components  = new Exercise("Working with Components", "React");
            Exercise Handshakes  = new Exercise("Proper Squeeze for Shaking Hands", "Soft Skills");

// Cohorts
            Cohort Cohort29 = new Cohort("29");
            Cohort Cohort30 = new Cohort("30");
            Cohort Cohort31 = new Cohort("31");

// Students
            Student Hank = new Student("Hank", "Hill", "@Propain", Cohort29);

            Cohort29.Students.Add(Hank);
            Student Finn = new Student("Finn", "Human", "@MATH", Cohort30);

            Cohort30.Students.Add(Finn);
            Student Larry = new Student("Larry", "David", "@PrettyGood", Cohort31);

            Cohort31.Students.Add(Larry);
            Student Dude = new Student("Dude", "Guy", "@Man", Cohort31);

            Cohort31.Students.Add(Dude);

// Instructors
            Instructor Andy = new Instructor("Andy", "Dude", "@Andy", Cohort29);

            Cohort29.Instructors.Add(Andy);
            Instructor Jissie = new Instructor("Jissie", "David", "@Jissie", Cohort30);

            Cohort30.Instructors.Add(Jissie);
            Instructor Leah = new Instructor("Leah", "Dudette", "@Leah", Cohort31);

            Cohort31.Instructors.Add(Leah);

// Using method from Instructor class to assign exercises to students
            Andy.AssignExercise(Hank, Gitstuff);
            Andy.AssignExercise(Hank, DomPractice);
            Jissie.AssignExercise(Finn, Gitstuff);
            Jissie.AssignExercise(Finn, Handshakes);
            Jissie.AssignExercise(Finn, Gitstuff);
            Leah.AssignExercise(Larry, Components);
            Leah.AssignExercise(Larry, Handshakes);

// List of all students
            List <Student> students = new List <Student>();

            students.Add(Hank);
            students.Add(Finn);
            students.Add(Larry);
            students.Add(Dude);
// List of all instructors
            List <Instructor> instructors = new List <Instructor>();

            instructors.Add(Andy);
            instructors.Add(Jissie);
            instructors.Add(Leah);
// List of all cohorts
            List <Cohort> cohorts = new List <Cohort>();

            cohorts.Add(Cohort29);
            cohorts.Add(Cohort30);
            cohorts.Add(Cohort31);
// List of all exercises
            List <Exercise> exercises = new List <Exercise>();

            exercises.Add(Gitstuff);
            exercises.Add(DomPractice);
            exercises.Add(Components);
            exercises.Add(Handshakes);

            Console.WriteLine($"Cohort {Cohort29.Name}");
            foreach (Student stu in Cohort29.Students)
            {
                Console.WriteLine($"{stu.FirstName} {stu.LastName}: | Slack Handle: {stu.Slack}");
            }

// Creating a list of all exercises with which students are assigned to said exercise
            Console.WriteLine();
            Console.WriteLine("Students Assigned to Exercises");
            Console.WriteLine();

            foreach (Exercise task in exercises)
            {
                List <string> studentsAssigned = new List <string>();
                foreach (Student guy in students)
                {
                    foreach (Exercise name in guy.Exercises)
                    {
                        if (name.Name == task.Name)
                        {
                            studentsAssigned.Add(guy.FirstName);
                        }
                    }
                }
                Console.WriteLine($"{task.Name}: {String.Join(", ", studentsAssigned)}");
            }

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

            Console.WriteLine("-----JS Exercises-----");

            foreach (Exercise exercise in JSExercises)
            {
                Console.WriteLine($"{exercise.Name}");
            }

            Console.WriteLine();
// List students in a particular cohort by using the Where() LINQ method.
            IEnumerable <Student> Cohort29Students = from student in students
                                                     where student.Cohort == Cohort29
                                                     select student;

            Console.WriteLine("-----Cohort29 Students-----");

            foreach (Student student in Cohort29Students)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            Console.WriteLine();
// List instructors in a particular cohort by using the Where() LINQ method.
            IEnumerable <Instructor> Cohort29Instructors = from instructor in instructors
                                                           where instructor.Cohort == Cohort29
                                                           select instructor;

            Console.WriteLine("-----Cohort29 Instructors-----");

            foreach (Instructor instructor in Cohort29Instructors)
            {
                Console.WriteLine($"{instructor.FirstName} {instructor.LastName}");
            }
            Console.WriteLine();
// Sort the students by their last name.
            IEnumerable <Student> AlphabetizedStudents = from student in students
                                                         orderby student.LastName ascending
                                                         select student;

            Console.WriteLine("-----Alphabetized Students-----");

            foreach (Student student in AlphabetizedStudents)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            Console.WriteLine();
// Display any students that aren't working on any exercises (Make sure one of your student instances doesn't have any exercises. Create a new student if you need to.)
            IEnumerable <Student> StudentsWithoutExercises = from student in students
                                                             where student.Exercises.Count() == 0
                                                             select student;

            Console.WriteLine("-----Students Without Exercises-----");

            foreach (Student student in StudentsWithoutExercises)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            Console.WriteLine();
// Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            IEnumerable <Student> StudentWithMostExercise = from student in students
                                                            orderby student.Exercises.Count()
                                                            select student;

            Console.WriteLine("-----Student With Most Exercises-----");

            Student MostExerciseStudent = StudentWithMostExercise.Last();

            Console.WriteLine($"{MostExerciseStudent.FirstName} {MostExerciseStudent.LastName}");

            Console.WriteLine();
// How many students in each cohort?
            Console.WriteLine("-----Cohort Student Count-----");

            foreach (Cohort cohort in cohorts)
            {
                Console.WriteLine($"{cohort.Name} {cohort.Students.Count()}");
            }
        }
コード例 #17
0
 // created a method that dds (assigns) an exercise to a student
 public void Assign(Student student, Exercise exercise)
 {
     student.ExerciseList.Add(exercise);
 }
コード例 #18
0
 public void AssignEx(Student student, Exercise ex)
 {
     student.StudentExerciseList.Add(ex);
     ex.Students.Add(student);
 }
コード例 #19
0
        static void Main(string[] args)
        {
            // exercises
            Exercise chickenMonkey   = new Exercise("Chicken Monkey", "Javascript");
            Exercise arrays          = new Exercise("Arrays", "Javascript");
            Exercise trackingStudent = new Exercise("Tracking Student Exercise", "C#");
            Exercise lists           = new Exercise("Lists", "C#");

            // create new cohorts
            Cohort twentyFive  = new Cohort("Cohort 25");
            Cohort twentySix   = new Cohort("Cohort 26");
            Cohort twentySeven = new Cohort("Cohort 27");

            // Create 4, or more, students and assign them to one of the cohorts.

            Student helen  = new Student("Helen", "Chalmers", "@survivor", twentySeven);
            Student austin = new Student("Austin", "Gorman", "@tallAss", twentySix);
            Student raf    = new Student("Rafael", "Cevallos", "@rifraf", twentyFive);
            Student jon    = new Student("Jonathan", "Elfers", "@numberOne", twentySeven);
            Student ricky  = new Student("Ricky", "Bruner", "@numberTwo", twentySeven);

            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor steve = new Instructor("Steve", "Brownlee", "@coach", twentySeven);
            Instructor jisie = new Instructor("Jisie", "David", "@jisie", twentySix);
            Instructor Joe   = new Instructor("Joe", "Joes", "@joe", twentyFive);

            // Have each instructor assign 2 exercises to each of the students.
            Joe.AssignExercise(chickenMonkey, helen);
            Joe.AssignExercise(arrays, austin);
            jisie.AssignExercise(lists, helen);
            jisie.AssignExercise(trackingStudent, raf);
            jisie.AssignExercise(arrays, raf);
            steve.AssignExercise(lists, raf);
            steve.AssignExercise(chickenMonkey, jon);

            List <Student> students = new List <Student>()
            {
                helen,
                austin,
                raf,
                jon,
                ricky
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                steve,
                jisie,
                Joe
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                twentyFive,
                twentySix,
                twentySeven
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                chickenMonkey,
                arrays,
                trackingStudent,
                lists
            };

// List exercises for the JavaScript language by using the Where() LINQ method.
            IEnumerable <Exercise> JsExercises = from e in exercises
                                                 where e.Language == "Javascript"
                                                 select e;

            JsExercises.ToList();

            foreach (Exercise n in JsExercises)
            {
                Console.WriteLine($" Exercises in JavaScript: {n.Name}");
            }
            Console.WriteLine("-------------");


// List students in a particular cohort by using the Where() LINQ method.

            IEnumerable <Student> studentInCohort27 = from s in students
                                                      where s.Cohort == twentySeven
                                                      select s;

            studentInCohort27.ToList();

            foreach (Student cohort27 in studentInCohort27)
            {
                Console.WriteLine($"{cohort27.FirstName} {cohort27.LastName} is in Cohort 27");
            }
            Console.WriteLine("-------------");

            IEnumerable <Student> studentsInCohort26 = from i in students
                                                       where i.Cohort == twentySix
                                                       select i;

            studentsInCohort26.ToList();
            foreach (Student cohort26 in studentsInCohort26)
            {
                Console.WriteLine($"{cohort26.FirstName} {cohort26.LastName} is in Cohort 26");
            }
            Console.WriteLine("-------------");
// List instructors in a particular cohort by using the Where() LINQ method.

            IEnumerable <Instructor> InstructorInCohort27 = from q in instructors
                                                            where q.Cohort == twentySeven
                                                            select q;

            InstructorInCohort27.ToList();

            foreach (Instructor Ins27 in InstructorInCohort27)
            {
                Console.WriteLine($"{Ins27.FirstName} {Ins27.LastName} teaches Cohort 27");
            }
            Console.WriteLine("-------------");

// Sort the students by their last name.

            IEnumerable <Student> studentLastAscending = students.OrderBy(stud => stud.LastName);

            foreach (var stud in studentLastAscending)
            {
                Console.WriteLine(stud.LastName);
            }
            Console.WriteLine("-------------");

// Display any students that aren't working on any exercises
// (Make sure one of your student instances don't have any exercises. Create a new student if you need to.)
            IEnumerable <Student> studentNone = students.Where(stude => stude.Exercises.Count() == 0).ToList();

            foreach (var stude in studentNone)
            {
                Console.WriteLine($"{stude.FirstName} {stude.LastName} insn't doing exercises!");
            }
            Console.WriteLine("-------------");

// Which student is working on the most exercises? Make sure one of your students has more exercises than the others.

// wtf I dont understand this at all


// How many students in each cohort?
            var howMany = students.GroupBy(c => c.Cohort.Name);

            foreach (var co in howMany)
            {
                Console.WriteLine($"{co.Key} has {co.Count()} students");
            }
        }
コード例 #20
0
 //create a method for assigning exercises to students.
 public void AssignExercise(Student student, Exercise exercise)
 {
     //Assign the student an exercise
     exercise.StudentList.Add(student);
     student.ExerciseList.Add(exercise);
 }
コード例 #21
0
        static void Main(string[] args)
        {
            Exercise nutshell = new Exercise {
                Name     = "Nutshell",
                Language = "Javascript"
            };
            Exercise nashville = new Exercise {
                Name     = "Welcome to Nashville",
                Language = "Javascript"
            };
            Exercise studentEx = new Exercise {
                Name     = "Student Exercises",
                Language = "C#"
            };
            Exercise boogers = new Exercise {
                Name     = "Boogers",
                Language = "Javascript"
            };
            Cohort CohortOne = new Cohort {
                name = "Cohort 1"
            };
            Cohort CohortTwo = new Cohort {
                name = "Cohort 2"
            };
            Cohort CohortThree = new Cohort {
                name = "Cohort 3"
            };
            Student Bobby = new Student {
                FirstName     = "Bobby",
                LastName      = "Fitzpatrick",
                SlackHandle   = "@BobFitz",
                CurrentCohort = CohortOne
            };
            Student Russ = new Student {
                FirstName     = "Russ",
                LastName      = "Miller",
                SlackHandle   = "@RussMill",
                CurrentCohort = CohortOne
            };
            Student Matt = new Student {
                FirstName     = "Matt",
                LastName      = "Rowe",
                SlackHandle   = "@DaRowe",
                CurrentCohort = CohortOne
            };
            Instructor Kim = new Instructor {
                FirstName     = "Kim",
                LastName      = "Preece",
                SlackHandle   = "@KimP",
                CurrentCohort = CohortOne
            };
            Instructor Josh = new Instructor {
                FirstName     = "Josh",
                LastName      = "Joseph",
                SlackHandle   = "@JoeJ",
                CurrentCohort = CohortOne
            };
            Instructor Jordan = new Instructor {
                FirstName     = "Jordan",
                LastName      = "Castelloe",
                SlackHandle   = "@JordC",
                CurrentCohort = CohortOne
            };

            Kim.AssignExercise(nutshell, Bobby);
            Josh.AssignExercise(nashville, Russ);
            Jordan.AssignExercise(boogers, Matt);
        }
コード例 #22
0
        static void Main(string[] args)
        {
            Exercise HolidayRoad = new Exercise()
            {
                Name     = "Holiday Road",
                Language = "C#"
            };
            Exercise Nutshell = new Exercise()
            {
                Name     = "Nutshell",
                Language = "React"
            };
            Exercise MartinsAquarium = new Exercise()
            {
                Name     = "Martin's Aquarium",
                Language = "JavaScript"
            };
            Exercise DailyJournal = new Exercise()
            {
                Name     = "Daily Journal",
                Language = ".NET"
            };


            Cohort Cohort1 = new Cohort()
            {
                Name = "Cohort 1"
            };

            Cohort Cohort2 = new Cohort()
            {
                Name = "Cohort 2"
            };

            Cohort Cohort3 = new Cohort()
            {
                Name = "Cohort 3"
            };

            List <Cohort> Cohorts = new List <Cohort>();

            Cohorts.Add(Cohort1);
            Cohorts.Add(Cohort2);
            Cohorts.Add(Cohort3);

            Student Audrey = new Student()
            {
                FirstName   = "Audrey",
                LastName    = "Borgra",
                SlackHandle = "@Audrey",
                Cohort      = Cohort1
            };

            Cohort1.addStudent(Audrey);

            Student James = new Student()
            {
                FirstName   = "James",
                LastName    = "Nitz",
                SlackHandle = "@James",
                Cohort      = Cohort2
            };

            Cohort2.addStudent(James);

            Student Kevin = new Student()
            {
                FirstName   = "Kevin",
                LastName    = "Penny",
                SlackHandle = "@Kevin",
                Cohort      = Cohort3
            };

            Cohort3.addStudent(Kevin);

            Student Willy = new Student()
            {
                FirstName   = "Willy",
                LastName    = "Metcalf",
                SlackHandle = "@Willy",
                Cohort      = Cohort3
            };

            Cohort3.addStudent(Willy);

            Student Daniel = new Student()
            {
                FirstName   = "Daniel",
                LastName    = "Bennett",
                SlackHandle = "@Daniel",
                Cohort      = Cohort3
            };

            Cohort3.addStudent(Daniel);


            Instructor Instructor1 = new Instructor()
            {
                FirstName   = "Albert",
                LastName    = "Einstein",
                SlackHandle = "@Instructor1",
                Cohort      = Cohort1,
                Speciality  = "The Cha Cha Slide"
            };

            Cohort1.addInstructor(Instructor1);
            Instructor1.AssignExercise(Audrey, HolidayRoad);
            Instructor1.AssignExercise(Audrey, Nutshell);

            Instructor Instructor2 = new Instructor()
            {
                FirstName   = "Miss",
                LastName    = "Frizzle",
                SlackHandle = "@Instructor2",
                Cohort      = Cohort2,
                Speciality  = "Electric Slide"
            };

            Cohort2.addInstructor(Instructor2);
            Instructor2.AssignExercise(James, MartinsAquarium);
            Instructor2.AssignExercise(James, DailyJournal);

            Instructor Instructor3 = new Instructor()
            {
                FirstName   = "Mister",
                LastName    = "Miyagi",
                SlackHandle = "@Instructor3",
                Cohort      = Cohort3,
                Speciality  = "Cupid Shuffle"
            };

            Cohort3.addInstructor(Instructor3);
            Instructor3.AssignExercise(Kevin, HolidayRoad);
            Instructor3.AssignExercise(Kevin, Nutshell);
            Instructor3.AssignExercise(Willy, MartinsAquarium);
            Instructor3.AssignExercise(Willy, DailyJournal);
            Instructor3.AssignExercise(Willy, HolidayRoad);

            List <Instructor> Instructors = new List <Instructor>();

            Instructors.Add(Instructor1);
            Instructors.Add(Instructor2);
            Instructors.Add(Instructor3);

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

            Students.Add(Audrey);
            Students.Add(James);
            Students.Add(Kevin);
            Students.Add(Willy);
            Students.Add(Daniel);

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

            Exercises.Add(HolidayRoad);
            Exercises.Add(Nutshell);
            Exercises.Add(MartinsAquarium);
            Exercises.Add(DailyJournal);

            foreach (Exercise exercise in Exercises)
            {
                Console.WriteLine($"{exercise.Name}:");
                foreach (Student student in Students)
                {
                    foreach (Exercise studentExercise in student.Exercises)
                    {
                        if (studentExercise == exercise)
                        {
                            Console.WriteLine($"{student.FirstName} {student.LastName}");
                        }
                    }
                }
                Console.WriteLine("");
            }

            var JavaScriptExercises = Exercises.Where(exercise => exercise.Language == "JavaScript");

            Console.WriteLine("These are the Javascript exercises:");

            foreach (var exercise in JavaScriptExercises)
            {
                Console.WriteLine($"{exercise.Name}");
            }
            Console.WriteLine("\n");

            foreach (var cohort in Cohorts)
            {
                var CohortStudents = Students.Where(student => student.Cohort == cohort);
                Console.WriteLine($"These are the students in {cohort.Name}:");
                foreach (var student in CohortStudents)
                {
                    Console.WriteLine($"{student.FirstName} {student.LastName}");
                }
                Console.WriteLine("\n");
                var CohortInstructors = Instructors.Where(instructor => instructor.Cohort == cohort);
                Console.WriteLine($"These are the instructors for {cohort.Name}:");
                foreach (var instructor in CohortInstructors)
                {
                    Console.WriteLine($"{instructor.FirstName} {instructor.LastName}");
                }
                Console.WriteLine("\n");
            }

            var studentsSorted = Students.OrderBy(student => student.LastName);

            Console.WriteLine("Here are the students sorted by last name:");
            foreach (var student in studentsSorted)
            {
                Console.WriteLine($"{student.LastName}, {student.FirstName}");
            }
            Console.WriteLine("\n");


            var StudentsWithoutExercises = Students.Where(student => student.Exercises.Count == 0);

            Console.WriteLine("These are the students that haven't been assigned any exercises:");
            foreach (var student in StudentsWithoutExercises)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }
            Console.WriteLine("\n");

            var MostExercises = Students.OrderByDescending(student => student.Exercises.Count).First();

            Console.WriteLine($"The student assigned the most exercises is {MostExercises.FirstName} {MostExercises.LastName}");
            Console.WriteLine("\n");

            foreach (var cohort in Cohorts)
            {
                var CohortStudents = Students.Where(student => student.Cohort == cohort);
                Console.WriteLine($"There are {CohortStudents.Count()} students in {cohort.Name}");
            }
            Console.WriteLine("\n");
        }
コード例 #23
0
// Assignment method thanks to Kimmy
        public void AssignStudent(Exercise Exercise, Student student)
        {
            student.StudentsExercises.Add(Exercise);
        }
コード例 #24
0
        static void Main(string[] args)
        {
            Cohort c26 = new Cohort("26");
            Cohort c27 = new Cohort("27");
            Cohort c28 = new Cohort("28");

            Exercise ex1 = new Exercise("FizzBuzz", "JavaScript");
            Exercise ex2 = new Exercise("Nutshell", "JavaScript");
            Exercise ex3 = new Exercise("Bangazon", "C#");
            Exercise ex4 = new Exercise("Weather", "React");

            Instructor Steve  = new Instructor("Steve", "Brownlee", "Steve", c26);
            Instructor Meg    = new Instructor("Meg", "Ducharme", "Meg", c27);
            Instructor Brenda = new Instructor("Brenda", "Long", "Brenda", c28);

            Student Daffy  = new Student("Daffy", "Duck", "Daf", c26);
            Student Dewey  = new Student("Dewey", "Duck", "Dew", c27);
            Student Donald = new Student("Donald", "Duck", "Don", c28);

            Steve.AssignExercise(ex1, Daffy);
            Meg.AssignExercise(ex2, Dewey);
            Meg.AssignExercise(ex4, Dewey);

            List <Student> students = new List <Student>()
            {
                Daffy, Dewey, Donald
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                ex1, ex2, ex3, ex4
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                Steve, Meg, Brenda
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                c26, c27, c28
            };



            Console.WriteLine($"-----------------");
            foreach (Student student in students)
            {
                foreach (Exercise exercise in exercises)
                {
                    if (student.Exercise.Contains(exercise))
                    {
                        Console.WriteLine($"{student.FirstName} {student.LastName} is working on {exercise.Name}");
                    }
                }
            }



            // 1. List exercises for the JavaScript language by using the Where() LINQ method.
            IEnumerable <Exercise> scripts = exercises.Where(exercise => exercise.Language == "JavaScript");

            Console.WriteLine($"-----------------");
            foreach (var script in scripts)
            {
                Console.WriteLine($"JavaScript exercises: {script.Name}");
            }



            // 2. List students in a particular cohort by using the Where() LINQ method.
            IEnumerable <Student> studentsIn26 = students.Where(student => student.Cohort == c26);

            Console.WriteLine($"-----------------");
            foreach (var student in studentsIn26)
            {
                Console.WriteLine($"Students in Cohort 26: {student.FirstName} {student.LastName}");
            }



            // 3. List instructors in a particular cohort by using the Where() LINQ method.
            IEnumerable <Instructor> instructorsIn27 = instructors.Where(instructor => instructor.Cohort == c27);

            Console.WriteLine($"-----------------");
            foreach (var instructor in instructorsIn27)
            {
                Console.WriteLine($"Instructors in Cohort 27: {instructor.FirstName} {instructor.LastName}");
            }



            // 4. Sort the students by their last name.
            IEnumerable <Student> sortedStudents = students.OrderBy(student => student.FirstName);

            Console.WriteLine($"-----------------");
            foreach (var student in sortedStudents)
            {
                Console.WriteLine($"Students sorted by last name: {student.FirstName} {student.LastName}");
            }



            // 5. Display any students that aren't working on any exercises (Make sure one of your student instances don't have any exercises. Create a new student if you need to.)
            IEnumerable <Student> studentsWithNoExercises = students.Where(student => student.Exercise.Count == 0);

            Console.WriteLine($"-----------------");
            foreach (var student in studentsWithNoExercises)
            {
                Console.WriteLine($"Students with no exercises: {student.FirstName} {student.LastName}");
            }



            // 6. Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            var studentWithMostExercises = (from student in students
                                            select new
            {
                FirstName = student.FirstName,
                Exercises = student.Exercise.Count
            })
                                           .OrderByDescending(student => student.Exercises)
                                           .Take(1).ToList()[0];

            Console.WriteLine($"-----------------");
            Console.WriteLine($"Student with the most exercises: {studentWithMostExercises.FirstName} {studentWithMostExercises.Exercises}");



            // 7. How many students in each cohort?
            // GroupBy gives you a collection of groups - each group has something that it's being grouped by (the key). The group itself is the list of all of the values of the group. Returns a collection of groups.
            // collection of groups (numberOfStudentsInEachCohort)
            var numberOfStudentsInEachCohort = students.GroupBy(cohort => cohort.Cohort.Name);

            Console.WriteLine($"-----------------");
            foreach (var studentGroup in numberOfStudentsInEachCohort)
            {
                Console.WriteLine($"{studentGroup.Key} has {studentGroup.Count()} student(s)");
            }



            Console.WriteLine($"-----------------");
            foreach (Exercise exercise in exercises)
            {
                List <string> assStudents = new List <string>();

                foreach (Student student in students)
                {
                    if (student.Exercise.Contains(exercise))
                    {
                        assStudents.Add(student.FirstName);
                    }
                }

                Console.WriteLine($"{exercise.Name} is being broken by {String.Join(", ", assStudents)}");
            }
        }
コード例 #25
0
 public void RemoveExercise(Exercise exercise, Student student)
 {
     student.ExerciseList.Remove(exercise);
 }
コード例 #26
0
        static void Main(string[] args)
        {
            // Create 4, or more, exercises.
            Exercise JSONparty     = new Exercise("JSON Party!", "JavaScript Object Notation");
            Exercise arrayMethods  = new Exercise("Array Methods", "JavaScript");
            Exercise asyncFuncs    = new Exercise("Asyncronous Functions", "JavaScript");
            Exercise flexFox       = new Exercise("FlexFox", "Cascading Style Sheets");
            Exercise hOOPs         = new Exercise("Object-Oriented B-Ball", "C#");
            Exercise functionsOnly = new Exercise("Side Effects May Include: NOTHING!!!!!!!!", "Haskell");
            // add them all to a list of exercises
            List <Exercise> exercises = new List <Exercise>()
            {
                JSONparty,
                functionsOnly,
                hOOPs,
                flexFox,
                arrayMethods,
                asyncFuncs,
            };

            // Create 3, or more, cohorts.
            Cohort day34   = new Cohort("day34");
            Cohort day35   = new Cohort("day35");
            Cohort day36   = new Cohort("day36");
            Cohort night11 = new Cohort("night11");
            // add them all to a List of cohorts
            List <Cohort> allCohorts = new List <Cohort>()
            {
                day34,
                day35,
                day36,
                night11,
            };

            // Create 4, or more, students
            Student JoeS       = new Student("Joe", "Snyder", "@real_JoeSchmoe");
            Student NoahB      = new Student("Noah", "Barfield", "@ArkAardvark");
            Student JacquelynM = new Student("Jacquelyn", "McCray", "@McCrayCray");
            Student EllieA     = new Student("Ellie", "Ash", "@kiss_my_ash");
            // add them all to a List of students
            List <Student> students = new List <Student>()
            {
                JoeS,
                NoahB,
                JacquelynM,
                EllieA,
            };

            // assign students to one of the cohorts.
            day34.Students.Add(JoeS);
            day34.Students.Add(NoahB);
            day34.Students.Add(JacquelynM);
            day34.Students.Add(EllieA);

            // Create 3, or more, instructors
            Instructor BryanN = new Instructor("Bryan", "Nielsen", "@Bry5", "day34");
            Instructor JennaS = new Instructor("Jenna", "Solis", "@alohaBroha", "day34");
            Instructor AndyC  = new Instructor("Andy", "Collins", "@tgwtglasses", "day34");
            Instructor AdamS  = new Instructor("Adam", "Scaffer", "@skiffSkaff", "day34");
            // add them all to a List of instructors
            List <Instructor> instructors = new List <Instructor>()
            {
                BryanN,
                JennaS,
                AndyC,
            };

            // add instructors to a cohort
            day34.Instructors.Add(BryanN);
            day34.Instructors.Add(JennaS);
            day34.Instructors.Add(AndyC);
            // Have each instructor assign 2 exercises to each of the students.
            AndyC.AssignExercise(JoeS, functionsOnly);
            AndyC.AssignExercise(JoeS, JSONparty);

            JennaS.AssignExercise(JacquelynM, asyncFuncs);
            JennaS.AssignExercise(JacquelynM, hOOPs);

            BryanN.AssignExercise(EllieA, flexFox);
            BryanN.AssignExercise(JacquelynM, flexFox);
            BryanN.AssignExercise(JacquelynM, arrayMethods);
            //-----------------------------------------------------------------------------
            // CHALLENGE
            // Create a list of students. Add all of the student instances to it.
            // DONE --- see above


            // Generate a report that displays which students are working on which exercises.
            foreach (Student student in students)
            {
                Console.WriteLine($"{student.FirstName} is working on:");
                if (student.StudentExercises.Count > 0)
                {
                    for (int i = 0; i < student.StudentExercises.Count; i++)
                    {
                        Console.WriteLine($"{i + 1}) {student.StudentExercises[i].ExerciseName}");
                    }
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("NOTHING");
                }
            }
            // List exercises for the JavaScript language by using the Where() LINQ method.
            var exercisesJS = exercises.Where(e => e.Language == "JavaScript");

            Console.WriteLine("------------------------------");
            Console.WriteLine("JS Exercises: ");
            Console.WriteLine("------------------------------");
            foreach (Exercise e in exercisesJS)
            {
                Console.WriteLine(e.ExerciseName);
            }
            ;

            // List students in a particular cohort by using the Where() LINQ method.

            // is there a way to add/set a property of a Student (or List of Students) instance
            //  when it is added to the ```List<Student> Students``` property of a Cohort class

            // specifically, i want to instantiate an instance of Student class
            // w/o setting the value of the CohortId property

            // THEN, add that Student to a particular Cohort, AT WHICH POINT:
            // the CohortID prop of the Student being added = the name of the name of the cohort they are being added to

            Student a = new Student("a", "aa", "@a");
            Student b = new Student("b", "bb", "@b");
            Student c = new Student("c", "cc", "@c");
            Student d = new Student("d", "dd", "@d");

            List <Student> night11Students = new List <Student>()
            {
                a,
                b,
                c,
                d,
            };


            night11.Students = night11Students;
            List <Student> allStudents = students.Concat(night11Students).ToList();

            Console.WriteLine("------------------------------");
            Console.WriteLine("Students in night-cohort-11: ");
            Console.WriteLine("------------------------------");

            foreach (Student s in night11Students)
            {
                Console.WriteLine($"{s.FirstName} {s.LastName}");
            }
            Console.WriteLine();


            // List instructors in a particular cohort by using the Where() LINQ method.
            List <Instructor> instructors34 = instructors.Where(i => i.Cohort == "day34").ToList();

            Console.WriteLine("+++++++++Instructors Assigned to Day Cohort 34+++++++++");
            foreach (Instructor i in instructors34)
            {
                Console.WriteLine($"{i.FirstName} {i.LastName}");
            }

            Console.WriteLine();
            Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine("all students - alphabetical sort by last name");
            // Sort the students by their last name.
            List <Student> alphaLastNameSort = allStudents.OrderBy(s => s.LastName).ToList();

            foreach (Student s in alphaLastNameSort)
            {
                Console.WriteLine($"{s.FirstName} {s.LastName}");
            }

            // Display any students that aren't working on any exercises (Make sure one of your student instances don't have any exercises. Create a new student if you need to.)
            List <Student> studentsNoExercises = allStudents.Where(s => s == null).ToList();

            foreach (Student s in studentsNoExercises)
            {
                Console.WriteLine($"{s.FirstName} {s.LastName}");
            }
            ;

            // Which student is working on the most exercises? Make sure one of your students has more exercises than the others.

            // var studentMostExercises = students.Select(s =>
            //     {
            //         return s.StudentExercises.Count();
            //     }
            // ).ToList();

            // foreach (int numExers in studentMostExercises)
            // {
            //     Console.WriteLine(numExers);
            // }

            // How many students in each cohort?
            var day34StudentCount = day34.Students.Count();
        }
コード例 #27
0
        static void Main(string[] args)
        {
            List <Student>    students    = new List <Student>();
            List <Exercise>   exercises   = new List <Exercise>();
            List <Instructor> instructors = new List <Instructor>();
            List <Cohort>     cohorts     = new List <Cohort>();

            //  Create 4, or more, exercises.
            Exercise exercise1 = new Exercise("Website", "HTML");
            Exercise exercise2 = new Exercise("Paint by Number", "CSS");
            Exercise exercise3 = new Exercise("Nutshell", "Javascript");
            Exercise exercise4 = new Exercise("Planets", "C#");
            Exercise exercise5 = new Exercise("OverlyExcited", "C#");
            Exercise exercise6 = new Exercise("SolarSystem", "C#");
            Exercise exercise7 = new Exercise("Carlot", "C#");
            Exercise exercise8 = new Exercise("DyanmicCards", "C#");

            exercises.Add(exercise1);
            exercises.Add(exercise2);
            exercises.Add(exercise3);
            exercises.Add(exercise4);
            exercises.Add(exercise5);
            exercises.Add(exercise6);
            exercises.Add(exercise7);
            exercises.Add(exercise8);

            // Create 3, or more, cohorts.
            Cohort cohort1 = new Cohort("Cohort 76");
            Cohort cohort2 = new Cohort("Cohort 77");
            Cohort cohort3 = new Cohort("Cohort 78");

            cohorts.Add(cohort1);
            cohorts.Add(cohort2);
            cohorts.Add(cohort3);


            // Create 4, or more, students and assign them to one of the cohorts.
            Student student1 = new Student("Sam", "Samson", "SamSam", 77);
            Student student2 = new Student("Kim", "Kimson", "KimKim", 78);
            Student student3 = new Student("Bob", "Bobson", "BobBob", 76);
            Student student4 = new Student("Ned", "Nedson", "NedNed", 77);
            Student student5 = new Student("Larry", "Larson", "LarLar", 77);
            Student student6 = new Student("Kristin", "Kristson", "KrisKris", 78);
            Student student7 = new Student("Loshanna", "Losson", "LosLos", 76);
            Student student8 = new Student("Tre", "Treson", "TreTre", 77);

            students.Add(student1);
            students.Add(student2);
            students.Add(student3);
            students.Add(student4);
            students.Add(student5);
            students.Add(student6);
            students.Add(student7);
            students.Add(student8);

            cohort2.Students.Add(student1);
            cohort3.Students.Add(student2);
            cohort1.Students.Add(student3);
            cohort2.Students.Add(student4);
            cohort2.Students.Add(student5);
            cohort3.Students.Add(student6);
            cohort1.Students.Add(student7);
            cohort2.Students.Add(student8);


            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor instructor1 = new Instructor("Mo", "Moson", "MoMo", 77, "Being Mo-mazing");
            Instructor instructor2 = new Instructor("Madie", "Madson", "MadMad", 78, "Being Mad-mazing");
            Instructor instructor3 = new Instructor("Adam", "Adamson", "AdAd", 77, "Being Ad-mazing");
            Instructor instructor4 = new Instructor("Brenda", "Brendson", "BrenBren", 76, "Being Bren-mazing");

            instructors.Add(instructor1);
            instructors.Add(instructor2);
            instructors.Add(instructor3);
            instructors.Add(instructor4);


            // Have each instructor assign 2 exercises to each of the students.
            instructor1.assign(student1, exercise1);
            instructor1.assign(student1, exercise3);
            instructor1.assign(student4, exercise2);
            instructor1.assign(student4, exercise4);

            instructor2.assign(student2, exercise2);
            instructor2.assign(student2, exercise4);

            instructor3.assign(student1, exercise2);
            instructor3.assign(student1, exercise4);
            instructor3.assign(student4, exercise3);
            instructor3.assign(student4, exercise1);

            instructor4.assign(student2, exercise1);
            instructor4.assign(student2, exercise3);
            instructor4.assign(student2, exercise4);
            instructor4.assign(student2, exercise5);
            instructor4.assign(student2, exercise6);

            // students.ForEach(student =>
            // {
            //     // for each  over exercises pushed up
            //     // look at the contains methods

            //     student.Exercises.ForEach(exercise =>
            //     {
            //         Console.WriteLine($"{student.FirstName} {student.LastName} is working on exercises {exercise.Name}");
            //     });

            // });


            /////////////////////////////////////////////////////////
            //**************Student Exercise/Part2****************//
            ///////////////////////////////////////////////////////

            // List exercises for the JavaScript language by using the Where() LINQ method.

            List <Exercise> javascriptExercise = exercises.Where(exercise => exercise.Language == "Javascript").ToList();

            javascriptExercise.ForEach(exercise =>
            {
                Console.WriteLine($"Javascript Exercise: {exercise.Name}");
            });
            Console.WriteLine("/////////////////////////////////////");

            // List students in a particular cohort by using the Where() LINQ method.
            List <Cohort> cohortNumber = cohorts.Where(cohort => cohort.CohortName == "Cohort 76").ToList();


            cohortNumber.ForEach(cohort =>
            {
                Console.WriteLine($"Cohort group: {cohort.CohortName}");

                cohort.Students.ForEach(student =>
                {
                    Console.WriteLine($"Students:{student.FirstName} {student.LastName}");
                });
            });
            Console.WriteLine("/////////////////////////////////////");

            // List instructors in a particular cohort by using the Where() LINQ method.
            List <Instructor> cohortInstructor = instructors.Where(instructor => instructor.CohortNumber == 77).ToList();

            cohortInstructor.ForEach(instructor =>
            {
                Console.WriteLine($"Instructors in {instructor.CohortNumber}: {instructor.FirstName} {instructor.LastName}");
            });

            Console.WriteLine("/////////////////////////////////////");
            // Sort the students by their last name.

            List <Student> Lstudent = students.Where(student => student.LastName.StartsWith("L")).ToList();

            Lstudent.ForEach(student =>
            {
                Console.WriteLine($"Lstudents: {student.LastName}, {student.FirstName}");
            });
            Console.WriteLine("/////////////////////////////////////");

            // Display any students that aren't working on any exercises

            List <Student> noExercises = students.Where(student => student.Exercises.Count == 0).ToList();

            noExercises.ForEach(student =>
            {
                Console.WriteLine($"All Students without an exercise: {student.LastName}, {student.FirstName}");
            });
            Console.WriteLine("/////////////////////////////////////");

            // Which student is working on the most exercises?

            List <Student> mostExercises = students.Where(student => student.Exercises.Count > 0).ToList();

            var busiestStudents = mostExercises.OrderBy(student => student.Exercises.Count).Last();

            Console.WriteLine($"Student with most exercises: {busiestStudents.FirstName} {busiestStudents.LastName}");
            Console.WriteLine("/////////////////////////////////////");

            // How many students in each cohort?
            var byCohort      = students.GroupBy(student => student.CohortNumber).ToList();
            var byCohortCount = byCohort.Count;

            Console.WriteLine(byCohortCount);


            byCohort.ForEach(cohort =>
            {
                Console.WriteLine($"There are {cohort.Count()} students in cohort {cohort.Key}");
            });
        }
コード例 #28
0
        static void Main(string[] args)
        {
            Cohort C30 = new Cohort("Cohort 30");
            Cohort E6  = new Cohort("Evening Cohort 6");
            Cohort C33 = new Cohort("Cohort 33");

            Student Praful = new Student("Prafullata", "Sonawane", "praful", C30);

            Student Janet = new Student("Janet", "Woods", "janet", C30);

            Student Nisha = new Student("Nisha", "Shah", "nisha", C33);

            Student Ryan = new Student("Steven", "D", "Steven", C33);

            Instructor Steve = new Instructor("Steve", "Brownlee", "steve", C30);
            Instructor Meg   = new Instructor("Meg", "D", "meg", E6);
            Instructor Jenna = new Instructor("Jenna", "Solis", "jenna", C30);
            Instructor Jessi = new Instructor("Jessi", "", "jessi", C33);

            C30.addInstructor(Steve);
            C30.addInstructor(Jenna);
            C30.addStudent(Praful);
            C30.addStudent(Janet);
            C33.addInstructor(Jessi);
            C33.addStudent(Ryan);
            C33.addStudent(Nisha);

            Exercise SolarSystem   = new Exercise("JS", "SolarSystem");
            Exercise OverlyExcited = new Exercise("JS", "Overly Excited");
            Exercise nutshell      = new Exercise("React", "Nutshell");
            Exercise addressBook   = new Exercise("C#", "Address Book");
            Exercise capstone      = new Exercise("React", "Capstone Project");

            Steve.assignExercise(SolarSystem, Praful);
            Steve.assignExercise(capstone, Praful);
            Jessi.assignExercise(nutshell, Ryan);
            Jessi.assignExercise(capstone, Nisha);
            Jenna.assignExercise(OverlyExcited, Janet);

            Console.WriteLine(Praful);
            Console.WriteLine(Nisha);
            Console.WriteLine(Steve);
            Console.WriteLine(Jessi);

            Console.WriteLine(C30);
            Console.WriteLine(C33);

            List <Student> students = new List <Student>()
            {
                Praful,
                Janet,
                Ryan,
                Nisha
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                SolarSystem,
                nutshell,
                addressBook,
                capstone
            };
            List <Instructor> instructors = new List <Instructor>()
            {
                Steve,
                Jenna,
                Jessi,
                Meg
            };
            List <Cohort> cohorts = new List <Cohort>()
            {
                C30,
                C33,
                E6
            };
            //List exercises for the JavaScript language by using the Where() LINQ method.
            IEnumerable <Exercise> JS_exercises = from exercise in exercises
                                                  where exercise.Language.Equals("JS")
                                                  select exercise;

            Console.WriteLine("Only JS exercises ---");
            foreach (Exercise ex in JS_exercises)
            {
                Console.WriteLine($"{ex.Name}");
            }
            ;
            //List students in a particular cohort by using the Where() LINQ method.
            //IEnumerable<Student> studentsC30 = from
        }
コード例 #29
0
        static void Main(string[] args)
        {
            Exercise MartinsAquarium = new Exercise("MartinsAquarium", "JavaScript");
            Exercise PlanYourHeist   = new Exercise("Plan Your Heist", "C#");
            Exercise GlassdalePD     = new Exercise("Glassdale PD", "JavaScript");
            Exercise Nutshell        = new Exercise("Nutshell", "React");

            Cohort Day37    = new Cohort("Day Cohort 37");
            Cohort Day39    = new Cohort("Day Cohort 39");
            Cohort Evening6 = new Cohort("Evening Cohort 6");

            Student SpencerT = new Student("Spencer", "Truett", "@Spencer Truett", Day37);
            Student DanielF  = new Student("Daniel", "Fuqua", "@Daniel Fuqua", Day39);
            Student HoldenP  = new Student("Holden", "Parker", "@Holden Parker", Day37);
            Student MattC    = new Student("Matt", "Crook", "@Matt Crook", Evening6);
            Student DouieN   = new Student("Douie", "Notheen", "@DoesNothing", Evening6);

            Instructor AdamS = new Instructor("Adam", "Sheaffer", "@adamsheaf", Day37)
            {
                Specialty = "Snacks"
            };

            AdamS.AssignExercise(MartinsAquarium, HoldenP);
            AdamS.AssignExercise(GlassdalePD, HoldenP);
            AdamS.AssignExercise(Nutshell, HoldenP);
            AdamS.AssignExercise(MartinsAquarium, SpencerT);
            AdamS.AssignExercise(GlassdalePD, SpencerT);

            Instructor MoS = new Instructor("Mo", "Silvera", "@Mo", Day39)
            {
                Specialty = "Dancing"
            };

            MoS.AssignExercise(PlanYourHeist, DanielF);
            MoS.AssignExercise(Nutshell, DanielF);

            Instructor SteveB = new Instructor("Steve", "Brownlee", "@coach", Evening6)
            {
                Specialty = "Dad Jokes"
            };

            SteveB.AssignExercise(Nutshell, MattC);
            SteveB.AssignExercise(MartinsAquarium, MattC);

            var AllStudents = new List <Student>()
            {
                SpencerT,
                DanielF,
                HoldenP,
                MattC,
                DouieN
            };

            var AllExercises = new List <Exercise>()
            {
                Nutshell,
                MartinsAquarium,
                GlassdalePD,
                PlanYourHeist
            };

            var AllInstructors = new List <Instructor>()
            {
                AdamS,
                SteveB,
                MoS
            };

            var AllCohorts = new List <Cohort>()
            {
                Day37,
                Day39,
                Evening6
            };

            foreach (Student student in AllStudents)
            {
                foreach (Exercise exercise in student.Exercises)
                {
                    Console.WriteLine($"{student.FirstName} is working on the {exercise.Name} {exercise.Language} exercise in {student.Cohort.Name}.");
                }
            }

            var javaScriptExercises = AllExercises.Where(exercise => exercise.Language == "JavaScript");

            foreach (var exercise in javaScriptExercises)
            {
                Console.WriteLine($"JavaScript exercise: {exercise.Name}");
            }

            var day37Students = AllStudents.Where(student => student.Cohort == Day37);

            foreach (var student in day37Students)
            {
                Console.WriteLine($"Student in day cohort 37: {student.FirstName} {student.LastName}");
            }

            var day37Instructors = AllInstructors.Where(instructor => instructor.Cohort == Day37);

            foreach (var instructor in day37Instructors)
            {
                Console.WriteLine($"Instructor in day cohort 37: {instructor.FirstName} {instructor.LastName}");
            }

            var studentsByLastName = AllStudents.OrderBy(student => student.LastName);

            Console.WriteLine("Students ordered by last name:");
            foreach (var student in studentsByLastName)
            {
                Console.Write($"{student.FirstName} {student.LastName} ");
            }

            var studentsNotWorking = AllStudents.Where(student => student.Exercises.Count() == 0);

            foreach (var student in studentsNotWorking)
            {
                Console.WriteLine($"Students not working on any exercises: {student.FirstName} {student.LastName}");
            }

            var descendStudentMostExercises = AllStudents.OrderByDescending(student => student.Exercises.Count());
            var studentMostExercises        = descendStudentMostExercises.First();

            Console.WriteLine($"{studentMostExercises.FirstName} {studentMostExercises.LastName} is currently working on the most exercises.");

            var groups = AllStudents.GroupBy(student => student.Cohort.Name);

            foreach (var group in groups)
            {
                Console.WriteLine($"There are {group.Count()} students in {group.Key}.");
            }
        }
コード例 #30
0
        static void Main(string[] args)
        {
            ExerciseList ExerciseList = new ExerciseList();

            Exercise Exercise1 = ExerciseList.createExercise("Dictionaries", "C#");
            Exercise Exercise2 = ExerciseList.createExercise("Lists", "C#");
            Exercise Exercise3 = ExerciseList.createExercise("Classes", "C#");
            Exercise Exercise4 = ExerciseList.createExercise("Student Exercises", "C#");

            CohortsList CohortList = new CohortsList();

            Cohort Cohort28 = CohortList.createCohort("Full Stack", "C28");
            Cohort Cohort29 = CohortList.createCohort("Full Stack", "C29");
            Cohort Cohort30 = CohortList.createCohort("Full Stack", "C30");
            Cohort Cohort31 = CohortList.createCohort("Full Stack", "C31");

            InstructorList InstructorList = new InstructorList();

            Instructor Instructor1 = InstructorList.createInstructor("Jisie", "David");
            Instructor Instructor2 = InstructorList.createInstructor("Andy", "Collins");
            Instructor Instructor3 = InstructorList.createInstructor("Kristin", "Norris");
            Instructor Instructor4 = InstructorList.createInstructor("Leah", "Hoefling");

            Instructor1.setSpecialty("Being blunt.");
            Instructor2.setSpecialty("Unknown.");
            Instructor3.setSpecialty("Snacks.");
            Instructor4.setSpecialty("Illustration.");
            Instructor1.SlackHandle = "@jisie";
            Instructor2.SlackHandle = "@andy";
            Instructor3.SlackHandle = "@kristin";
            Instructor4.SlackHandle = "@leah";
            foreach (Instructor Instructor in InstructorList.getAll())
            {
                Cohort31.Assign(Instructor);
            }

            StudentList StudentList = new StudentList();

            Student Student1 = StudentList.createStudent("Anne", "Vick");
            Student Student2 = StudentList.createStudent("Jameka", "Echols");
            Student Student3 = StudentList.createStudent("Chris", "Morgan");
            Student Student4 = StudentList.createStudent("Meag", "Mueller");

            Student1.SlackHandle = "@anne";
            Student2.SlackHandle = "@jameka";
            Student3.SlackHandle = "@chris";
            Student4.SlackHandle = "@meag";
            foreach (Student Student in StudentList.getAll())
            {
                Cohort31.Assign(Student);
            }

            foreach (Student Student in StudentList.getAll())
            {
                Instructor1.AssignExercise(Student, Exercise1);
                Instructor2.AssignExercise(Student, Exercise2);
                Instructor3.AssignExercise(Student, Exercise3);
                Instructor4.AssignExercise(Student, Exercise4);
            }

            foreach (Cohort Cohort in CohortList.AllCohorts())
            {
                Console.WriteLine(Cohort.printInfo());
                Console.WriteLine("-----------------");
            }

            Console.WriteLine("--------------------------");
            Console.WriteLine("PART 2");
            Console.WriteLine("--------------------------");

            Cohort30.Assign(StudentList.createStudent("Larry", "Larryson"));
            Cohort30.Assign(StudentList.createStudent("Kristen", "Kristinson"));
            Cohort30.Assign(StudentList.createStudent("Loshanna", "Loshannason"));
            Cohort30.Assign(StudentList.createStudent("Tre", "Treson"));
            Cohort30.Assign(StudentList.createStudent("Overachieving", "Asshat"));

            ExerciseList.createExercise("OverlyExcited", "Javascript");
            ExerciseList.createExercise("SolarSystem", "Javascript");
            ExerciseList.createExercise("CarLot", "Javascript");
            ExerciseList.createExercise("DynamicCards", "Javascript");

            Cohort30.Assign(InstructorList.createInstructor("Idont", "Remember"));
            Cohort30.Assign(InstructorList.createInstructor("Who", "Taught"));
            Cohort30.Assign(InstructorList.createInstructor("Cohort", "Thirty"));

            //note to self: never do it like this again. Just wanted to see if I could keep it all straight in my head long enough to type out working code.
            //for each student wher student cohort is cohort 30, iterate through a list of exercies that are of the javascript langauge and assign those to the student.
            StudentList.getAll().Where(student => student.Cohort() == Cohort30.Name()).ToList().ForEach(student => ExerciseList.getAll().Where(exercise => exercise.Language() == "Javascript").ToList().ForEach(exercise => student.Assign(exercise)));

            Student Overachiever = StudentList.getAll().First(Student => Student.Name() == "Overachieving Asshat");

            ExerciseList.getAll().Where(exercise => exercise.Language() == "C#").ToList().ForEach(exercise => Overachiever.Assign(exercise));

            Cohort30.Assign(StudentList.createStudent("Lazy", "Asshole"));

            Console.WriteLine("All javascript exercises");
            //For all exercises where javascript is the language, write out the name of the exercise and its langauge.
            ExerciseList.getAll().Where(exercise => exercise.Language() == "Javascript").ToList().ForEach(exercise => Console.WriteLine($"{exercise.Name()} is in {exercise.Language()}"));
            Console.WriteLine("----------------------");

            Console.WriteLine("All students in Cohort 30");
            StudentList.getAll().Where(student => student.Cohort() == Cohort30.Name()).ToList().ForEach(student => Console.WriteLine($"{student.Name()} is in {student.Cohort()}"));
            Console.WriteLine("----------------------");

            Console.WriteLine("All Instructors in Cohort 30");
            InstructorList.getAll().Where(instructor => instructor.Cohort() == Cohort30.Name()).ToList().ForEach(instructor => Console.WriteLine($"{instructor.Name()} is in {instructor.Cohort()}"));
            Console.WriteLine("----------------------");
            Console.WriteLine("All students sorted by LastName");
            StudentList.getAll().OrderBy(student => student.LastName()).ToList().ForEach(student => Console.WriteLine($"{student.LastName()}, {student.FirstName()}"));

            Console.WriteLine("----------------------");
            Console.WriteLine("All students working on 0 exercises:");
            StudentList.getAll().Where(student => student.ExerciseList().Count == 0).ToList().ForEach(student => Console.WriteLine(student.Name()));

            Console.WriteLine("----------------------");
            Console.WriteLine("The student working on the most exercises:");
            int MaxExercises = StudentList.getAll().Select(student => student.ExerciseList().Count).Max();

            Console.WriteLine(StudentList.getAll().First(student => student.ExerciseList().Count == MaxExercises).Name());

            Console.WriteLine("----------------------");
            Console.WriteLine("The number of students in each cohort:");
            IEnumerable <EnrollmentReport> enrollmentReports = CohortList.AllCohorts().Select(cohort => new EnrollmentReport {
                CohortName   = cohort.Name(),
                StudentCount = StudentList.getAll().Where(student => student.Cohort() == cohort.Name()).ToList().Count
            });

            foreach (EnrollmentReport report in enrollmentReports)
            {
                Console.WriteLine($"{report.CohortName} has {report.StudentCount} students.");
            }
        }