示例#1
0
        static void Main(string[] args)
        {
            var chickenMonkey = new Exercise("ChickenMonkey", "JS");
            var employees     = new Exercise("Company Employees", "C#");
            var stocks        = new Exercise("Stock Exchange", "C#");
            var dailyJournal  = new Exercise("Daily Journal", "React");

            var cohort32 = new Cohort("Cohort 32");
            var cohort28 = new Cohort("Cohort 28");
            var cohort34 = new Cohort("Cohort 34");

            var deep   = new Student("Deep", "Patel", "DP", cohort32);
            var joey   = new Student("Joey", "Driscoll", "JD", cohort32);
            var jason  = new Student("Jason", "Collum", "JC", cohort28);
            var collin = new Student("Collin", "Sandlin", "CS", cohort28);
            var dan    = new Student("Dan", "Storm", "DS", cohort34);
            var sean   = new Student("Sean", "Glavin", "SG", cohort34);

            var adam = new Instructor()
            {
                FirstName   = "Adam",
                LastName    = "Sheaffer",
                SlackHandle = "ADM",
                CohortName  = cohort32,
                Specialty   = "Type Script"
            };

            var bryan = new Instructor()
            {
                FirstName   = "Bryan",
                LastName    = "Neilson",
                SlackHandle = "BRYN",
                CohortName  = cohort34,
                Specialty   = "High Fives"
            };

            var steve = new Instructor()
            {
                FirstName   = "Steve",
                LastName    = "Brownlee",
                SlackHandle = "STV",
                CohortName  = cohort28,
                Specialty   = "Coach"
            };

            adam.AddExercise(deep, employees);
            adam.AddExercise(deep, stocks);
            bryan.AddExercise(deep, chickenMonkey);
            bryan.AddExercise(deep, dailyJournal);
            steve.AddExercise(deep, employees);
            steve.AddExercise(deep, stocks);

            adam.AddExercise(joey, employees);
            adam.AddExercise(joey, stocks);
            bryan.AddExercise(joey, chickenMonkey);
            bryan.AddExercise(joey, dailyJournal);
            steve.AddExercise(joey, employees);
            steve.AddExercise(joey, stocks);

            adam.AddExercise(jason, employees);
            adam.AddExercise(jason, stocks);
            bryan.AddExercise(jason, chickenMonkey);
            bryan.AddExercise(jason, dailyJournal);
            steve.AddExercise(jason, employees);
            steve.AddExercise(jason, stocks);

            adam.AddExercise(collin, employees);
            adam.AddExercise(collin, stocks);
            bryan.AddExercise(collin, chickenMonkey);
            bryan.AddExercise(collin, dailyJournal);
            steve.AddExercise(collin, employees);
            steve.AddExercise(collin, stocks);

            adam.AddExercise(dan, employees);
            adam.AddExercise(dan, stocks);
            bryan.AddExercise(dan, chickenMonkey);
            bryan.AddExercise(dan, dailyJournal);
            steve.AddExercise(dan, employees);
            steve.AddExercise(dan, stocks);

            adam.AddExercise(sean, employees);
            adam.AddExercise(sean, stocks);
            bryan.AddExercise(sean, chickenMonkey);
            bryan.AddExercise(sean, dailyJournal);
            steve.AddExercise(sean, employees);
            steve.AddExercise(sean, stocks);

            var students  = new List <Student>();
            var exercises = new List <Exercise>();

            students.Add(deep);
            students.Add(joey);
            students.Add(jason);
            students.Add(collin);
            students.Add(dan);
            students.Add(sean);

            exercises.Add(chickenMonkey);
            exercises.Add(employees);
            exercises.Add(stocks);
            exercises.Add(dailyJournal);

            // foreach (Student student in students)
            // {
            //     Console.WriteLine($"{student.FirstName} {student.LastName} is working on:");
            //     student.ShowExercises();
            //     Console.WriteLine("");
            // }

            foreach (Exercise exercise in exercises)
            {
                Console.WriteLine($"These students are working on {exercise.Name}:");

                foreach (Student student in students)
                {
                    if (student.Exercises.Contains(exercise))
                    {
                        Console.WriteLine($"{student.FirstName}");
                    }
                }
                Console.WriteLine("");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            var chickenMonkey = new Exercise("ChickenMonkey", "JS");
            var employees     = new Exercise("Company Employees", "C#");
            var stocks        = new Exercise("Stock Exchange", "C#");
            var dailyJournal  = new Exercise("Daily Journal", "React");
            var planner       = new Exercise("Planner", "C#");

            var cohort32 = new Cohort("Cohort 32");
            var cohort28 = new Cohort("Cohort 28");
            var cohort34 = new Cohort("Cohort 34");

            var deep   = new Student("Deep", "Patel", "DP", cohort32);
            var joey   = new Student("Joey", "Driscoll", "JD", cohort32);
            var jason  = new Student("Jason", "Collum", "JC", cohort28);
            var collin = new Student("Collin", "Sandlin", "CS", cohort28);
            var dan    = new Student("Dan", "Storm", "DS", cohort34);
            var sean   = new Student("Sean", "Glavin", "SG", cohort34);

            var adam = new Instructor()
            {
                FirstName   = "Adam",
                LastName    = "Sheaffer",
                SlackHandle = "ADM",
                CohortName  = cohort32,
                Specialty   = "Type Script"
            };

            var bryan = new Instructor()
            {
                FirstName   = "Bryan",
                LastName    = "Neilson",
                SlackHandle = "BRYN",
                CohortName  = cohort34,
                Specialty   = "High Fives"
            };

            var steve = new Instructor()
            {
                FirstName   = "Steve",
                LastName    = "Brownlee",
                SlackHandle = "STV",
                CohortName  = cohort28,
                Specialty   = "Coach"
            };

            adam.AddExercise(deep, employees);
            adam.AddExercise(deep, stocks);
            bryan.AddExercise(deep, chickenMonkey);
            bryan.AddExercise(deep, dailyJournal);
            steve.AddExercise(deep, employees);
            steve.AddExercise(deep, stocks);

            adam.AddExercise(joey, employees);
            adam.AddExercise(joey, stocks);
            bryan.AddExercise(joey, chickenMonkey);
            bryan.AddExercise(joey, dailyJournal);
            steve.AddExercise(joey, employees);
            steve.AddExercise(joey, stocks);

            adam.AddExercise(jason, employees);
            adam.AddExercise(jason, stocks);
            bryan.AddExercise(jason, chickenMonkey);
            bryan.AddExercise(jason, dailyJournal);
            steve.AddExercise(jason, employees);
            steve.AddExercise(jason, stocks);
            steve.AddExercise(jason, planner);

            adam.AddExercise(collin, employees);
            adam.AddExercise(collin, stocks);
            bryan.AddExercise(collin, chickenMonkey);
            bryan.AddExercise(collin, dailyJournal);
            steve.AddExercise(collin, employees);
            steve.AddExercise(collin, stocks);

            // adam.AddExercise(dan, employees);
            // adam.AddExercise(dan, stocks);
            // bryan.AddExercise(dan, chickenMonkey);
            // bryan.AddExercise(dan, dailyJournal);
            // steve.AddExercise(dan, employees);
            // steve.AddExercise(dan, stocks);

            adam.AddExercise(sean, employees);
            adam.AddExercise(sean, stocks);
            bryan.AddExercise(sean, chickenMonkey);
            bryan.AddExercise(sean, dailyJournal);
            steve.AddExercise(sean, employees);
            steve.AddExercise(sean, stocks);

            // var students = new List<Student>();
            // var exercises = new List<Exercise>();

            // students.Add(deep);
            // students.Add(joey);
            // students.Add(jason);
            // students.Add(collin);
            // students.Add(dan);
            // students.Add(sean);

            // exercises.Add(chickenMonkey);
            // exercises.Add(employees);
            // exercises.Add(stocks);
            // exercises.Add(dailyJournal);

            var students = new List <Student>()
            {
                deep,
                joey,
                jason,
                collin,
                dan,
                sean
            };

            var exercises = new List <Exercise>()
            {
                chickenMonkey,
                dailyJournal,
                employees,
                stocks
            };

            var instructors = new List <Instructor>()
            {
                steve,
                adam,
                bryan
            };

            var cohorts = new List <Cohort>()
            {
                cohort28,
                cohort32,
                cohort34
            };

            List <Exercise> javaScript =
                (from exercise in exercises
                 where exercise.Language == "JS"
                 select exercise
                ).ToList();

            List <Student> cohort32Students =
                (from student in students
                 where student.CohortName == cohort32
                 select student
                ).ToList();

            List <Instructor> cohort32Instructors =
                (from instructor in instructors
                 where instructor.CohortName == cohort32
                 select instructor
                ).ToList();

            List <Student> alphabetical = students.OrderBy(student => student.LastName).ToList();

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

            List <Student> noExercises =
                (from student in students
                 where student.Exercises.Count() == 0
                 select student
                ).ToList();

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

            List <Student> mostExercises =
                (from student in students
                 //  where student.Exercises.Count()
                 orderby student.Exercises.Count() descending
                 select student
                ).ToList();

            Console.WriteLine($"{mostExercises[0].FirstName} is doing the most exercises");

            List <CohortReport> reports =
                (from student in students
                 group student by student.CohortName into studentGroup
                 select new CohortReport
            {
                CohortName = studentGroup.Key.Name,
                NumberOfStudents = studentGroup.Count()
            }
                ).ToList();

            foreach (CohortReport report in reports)
            {
                Console.WriteLine($"{report.CohortName} has {report.NumberOfStudents} students in it");
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            Exercise classes = new Exercise();

            classes.id             = 1;
            classes.nameOfExercise = "Classes in C#";
            classes.language       = "C#";

            Exercise lists = new Exercise();

            lists.id             = 2;
            lists.nameOfExercise = "Lists in C#";
            lists.language       = "C#";

            Exercise dailyJournal = new Exercise();

            dailyJournal.id             = 3;
            dailyJournal.nameOfExercise = "Daily Journal";
            dailyJournal.language       = "Javascript";

            Exercise watched = new Exercise();

            watched.id             = 4;
            watched.nameOfExercise = "Watched";
            watched.language       = "React";

            Cohort cohortOne = new Cohort();

            cohortOne.id         = 1;
            cohortOne.cohortName = "Cohort One";

            Cohort cohortTwo = new Cohort();

            cohortTwo.id         = 2;
            cohortTwo.cohortName = "Cohort Two";

            Cohort cohortThree = new Cohort();

            cohortThree.id         = 3;
            cohortThree.cohortName = "Cohort Three";

            Student alex = new Student()
            {
                id          = 1,
                firstName   = "Alex",
                lastName    = "Franklin",
                slackHandle = "Alex Franklin",
                Cohort      = cohortTwo,
                // cohortTwo.studentsInCohortList.Add(alex);
            };

            Student sable = new Student();

            sable.id          = 2;
            sable.firstName   = "Sable";
            sable.lastName    = "SAAAAAAAABLE";
            sable.slackHandle = "Sabs";
            sable.Cohort      = cohortOne;
            // cohortOne.studentsInCohortList.Add(sable);

            Student tommy = new Student();

            tommy.id          = 3;
            tommy.firstName   = "Tommy";
            tommy.lastName    = "Ymmot";
            tommy.slackHandle = "TomTom";
            tommy.Cohort      = cohortOne;
            // cohortOne.studentsInCohortList.Add(tommy);

            Student frank = new Student();

            frank.id          = 4;
            frank.firstName   = "Frank";
            frank.lastName    = "Knarf";
            frank.slackHandle = "FrankenFrank";
            frank.Cohort      = cohortThree;
            // cohortThree.studentsInCohortList.Add(frank);

            Student steve = new Student()
            {
                firstName   = "Steve",
                lastName    = "evetS",
                slackHandle = "Stevers",
                Cohort      = cohortThree,
            };


            cohortTwo.studentsInCohortList.Add(alex);
            cohortOne.studentsInCohortList.Add(sable);
            cohortOne.studentsInCohortList.Add(tommy);
            cohortThree.studentsInCohortList.Add(frank);

            Instructor jordan = new Instructor();

            jordan.id          = 1;
            jordan.firstName   = "Jordan";
            jordan.lastName    = "Nadroj";
            jordan.Cohort      = cohortOne;
            jordan.slackHandle = "Jordan";
            jordan.specialty   = "Wizardry";
            // cohortOne.instructorsInCohortList.Add(jordan);
            jordan.AddExercise(watched, sable);
            jordan.AddExercise(lists, tommy);



            Instructor instructorTommy = new Instructor();

            instructorTommy.id          = 2;
            instructorTommy.firstName   = "Tommy";
            instructorTommy.lastName    = "Ymmot";
            instructorTommy.Cohort      = cohortTwo;
            instructorTommy.slackHandle = "Tommmmmmmy";
            instructorTommy.specialty   = "Specialized in Charisma";
            // cohortTwo.instructorsInCohortList.Add(instructorTommy);
            instructorTommy.AddExercise(watched, alex);
            instructorTommy.AddExercise(lists, alex);


            Instructor josh = new Instructor();

            josh.id          = 1;
            josh.firstName   = "Josh";
            josh.lastName    = "Hsoj";
            josh.Cohort      = cohortThree;
            josh.slackHandle = "Joshington";
            josh.specialty   = "Beard";
            // cohortThree.instructorsInCohortList.Add(josh);
            josh.AddExercise(classes, frank);
            josh.AddExercise(dailyJournal, frank);
            josh.AddExercise(lists, frank);
            josh.AddExercise(watched, frank);


            cohortOne.instructorsInCohortList.Add(jordan);
            cohortTwo.instructorsInCohortList.Add(instructorTommy);
            cohortThree.instructorsInCohortList.Add(josh);

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

            students.Add(alex);
            students.Add(sable);
            students.Add(frank);
            students.Add(tommy);
            students.Add(steve);

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

            exercises.Add(classes);
            exercises.Add(lists);
            exercises.Add(watched);
            exercises.Add(dailyJournal);

            List <Instructor> instructors = new List <Instructor>()
            {
                instructorTommy, jordan, josh
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                cohortOne, cohortTwo, cohortThree
            };

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

            IEnumerable <Exercise> JavascriptExercises = exercises.Where(exercises => exercises.language == "Javascript");

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

            IEnumerable <Student> studentsInCohortOne = students.Where(student => student.Cohort == cohortOne);

            // foreach (Student student in studentsInCohortOne)
            // {
            //     Console.WriteLine(student.firstName);
            // }

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

            IEnumerable <Instructor> instructorsInCohortOne = instructors.Where(instructor => instructor.Cohort == cohortOne);

            // foreach (Instructor instructor in instructorsInCohortOne)
            // {
            //     Console.WriteLine(instructor.firstName);
            // }

            // Sort the students by their last name.

            IEnumerable <Student> studentsSorted = students.OrderBy(student => student.lastName).ToList();


            // foreach (Student student in studentsSorted)
            // {
            //     Console.WriteLine(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.)

            IEnumerable <Student> lazyBois = students.Where(student => student.currentExercises.Count == 0);

            // foreach (Student s in lazyBois)
            // {
            //     Console.WriteLine(s.firstName);
            // }

            IEnumerable <Student> studentsOrderedByCurrentExerciseCount = students.OrderByDescending(student => student.currentExercises.Count());

            Student hardestWorkinBoi = studentsOrderedByCurrentExerciseCount.Last();

            // Console.WriteLine(hardestWorkinBoi.firstName);

            // How many students in each cohort?

            IEnumerable <Cohort> cohortsOrderedByDescending = cohorts.OrderByDescending(cohorts => cohorts.studentsInCohortList.Count());

            foreach (Cohort cohort in cohortsOrderedByDescending)
            {
                Console.WriteLine($"{cohort.cohortName} has {cohort.studentsInCohortList.Count()} students in it!");
            }



            // foreach (Exercise currentExercise in exercises)
            // {
            //     Console.WriteLine(currentExercise.nameOfExercise);
            //     Console.WriteLine("---------");
            //     List<Student> assignedStudents = students.Where(singleStudent => singleStudent.currentExercises.Any(singleExercise => singleExercise.nameOfExercise == currentExercise.nameOfExercise)).ToList();

            //     assignedStudents.ForEach(singleStudent => Console.WriteLine(singleStudent.firstName));
            //     Console.WriteLine();
            // }
        }