static void Main(string[] args)
        {
            // Verify that the tables exist in the database
            Student.CheckTable();
            Cohort.CheckTable();

            // Get all students
            Student.Get().ForEach(Console.WriteLine);

            // Choice will hold the number entered by the user
            // after main menu ws displayed
            int choice;

            do
            {
                // Show the main menu
                choice = MainMenu.Show();

                switch (choice)
                {
                // Menu option 1: Adding cohort
                case 1:
                    StudentController.Create();
                    break;

                // Menu option 2: Adding student
                case 2:
                    StudentController.Create();
                    break;
                }
            } while (choice != 5);

            /*
             *  1. Create Exercises table and seed it
             *  2. Create Student table and seed it  (use sub-selects)
             *  3. Create StudentExercise table and seed it (use sub-selects)
             *  4. List the instructors and students assigned to each cohort
             *  5. List the students working on each exercise, include the
             *     student's cohort and the instructor who assigned the exercise
             */
        }
Beispiel #2
0
        /************************************************************************************
        * COHORTS:
        ************************************************************************************/

        public List <Cohort> GETALLCOHORTS()
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();

                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT Id, Designation FROM Cohort";

                    SqlDataReader reader = cmd.ExecuteReader();

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


                    while (reader.Read())
                    {
                        int idColumnPosition = reader.GetOrdinal("Id");
                        int idValue          = reader.GetInt32(idColumnPosition);

                        int    DesignationColumnPosition = reader.GetOrdinal("Designation");
                        string DesignationValue          = reader.GetString(DesignationColumnPosition);

                        Cohort cohort = new Cohort
                        {
                            Id          = idValue,
                            Designation = DesignationValue
                        };

                        allCohortList.Add(cohort);
                    }

                    reader.Close();

                    return(allCohortList);
                }
            }
        }
Beispiel #3
0
        /*
         *  A student can only be in one cohort at a time
         *  A student can be working on many exercises at a time
         */
        public Student(string argStuFirstName, string argStuLastName, string argStuSlack, Cohort argStuCohort)
        {
            stuFirstName = argStuFirstName;
            stuLastName  = argStuLastName;
            stuSlack     = argStuSlack;
            Cohort       = argStuCohort;
            Assignment   = new List <Exercise>();
            // Without a Cohort type defined here, the student cannot be sorted by the "string cohort" or stuCohort defined as a property below.

            // Console.WriteLine($"{stuFirstName} {stuLastName}, {stuSlack}, Cohort {Cohort.cohortName}");
        }
        /*
         *     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.
         */
        static void Main(string[] args)
        {
            //Make 4 exercises using the exercise type
            Exercise e1 = new Exercise("Objects", "javascript");
            Exercise e2 = new Exercise("Student Exercise", "c#");
            Exercise e3 = new Exercise("Kennel", "react.js");
            Exercise e4 = new Exercise("chickenMonkey", "javascript");

            Cohort c34 = new Cohort("c34");
            Cohort c35 = new Cohort("c35");
            Cohort c36 = new Cohort("c36");
            Cohort c39 = new Cohort("c39");

            Student Bill = new Student("Bill", "Brown", "Willy", c34);
            Student Hank = new Student("Hank", "Yellow", "where", c35);
            Student Sam  = new Student("Sam", "Green", "what", c36);
            Student Gene = new Student("Gene", "ferdy", "who", c39);

            c34.StudentList.Add(Bill);
            c35.StudentList.Add(Hank);
            c36.StudentList.Add(Sam);
            c39.StudentList.Add(Gene);

            Instructor Adam  = new Instructor("Adam", "shaffer", "shaffy", c35, "Eating IceCream");
            Instructor Jisie = new Instructor("Jisie", "Dont know", "hmmm", c39, "Coding");

            Instructor Maddie = new Instructor("Maddie", "slackname", "mads", c36, "dancing");
            Instructor Jenna  = new Instructor("Jenna", "no clue", "Jenn", c34, "Beat boxing");

            //adding instructors to the list of instructors
            c35.InstructorList.Add(Adam);
            c36.InstructorList.Add(Maddie);
            c39.InstructorList.Add(Jisie);
            c34.InstructorList.Add(Jenna);

            // Cohort 35
            Adam.AssignExercise(Hank, e1);
            Adam.AssignExercise(Hank, e2);

            // Cohort 39
            Jisie.AssignExercise(Gene, e3);
            Jisie.AssignExercise(Gene, e4);

            // Cohort 34
            Jenna.AssignExercise(Bill, e3);

            Jenna.AssignExercise(Bill, e4);

            /// Cohort 36
            Maddie.AssignExercise(Sam, e2);
            Maddie.AssignExercise(Sam, e1);

            List <Student> students = new List <Student>
            {
                Bill,
                Sam,
                Hank,
                Gene
            };

            List <Exercise> exercises = new List <Exercise>
            {
                e1,
                e2,
                e3,
                e4,
            };

            foreach (Student student in students)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName} is working on these exercises:");
                foreach (Exercise studentExercise in student.StudentExerciseList)
                {
                    Console.WriteLine($"{studentExercise.Name}");
                }
                Console.WriteLine("");
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Exercise ChickenMonkey    = new Exercise("Chicken Monkey", "Javascript");
            Exercise CoinsToCash      = new Exercise("Coins to Cash", "Javascript");
            Exercise StudentExercises = new Exercise("Student Exercises", "C#");
            Exercise Nutshell         = new Exercise("Nutshell", "C#");

            Cohort ThirtyFour = new Cohort("34");
            Cohort ThirtyFive = new Cohort("35");
            Cohort ThirtySix  = new Cohort("36");

            Student Will     = new Student("Will", "Wilkerson", "WILLSLACK");
            Student Noah     = new Student("Noah", "Bartfield", "NOAHSLACK");
            Student Brantley = new Student("Brantley", "Jones", "BRANTLEYSLACK");
            Student Bobby    = new Student("Bobby", "Brady", "BOBBYSLACK");
            Student Ted      = new Student("Ted", "Rooselvelt", "TEDSLACK");

            ThirtyFive.AddStudent(Will);
            ThirtyFive.AddStudent(Brantley);
            ThirtyFour.AddStudent(Noah);
            ThirtySix.AddStudent(Bobby);
            ThirtySix.AddStudent(Ted);

            Instructor Andy  = new Instructor("Andy", "Collins", "ANDYSLACK", "Pointing");
            Instructor Jenna = new Instructor("Jenna", "Solis", "JENNASLACK", "Killing animals");
            Instructor Bryan = new Instructor("Bryan", "Nilsen", "ANDYSLACK", "High fives");

            ThirtyFive.AddInstructor(Andy);
            ThirtySix.AddInstructor(Jenna);
            ThirtyFour.AddInstructor(Bryan);

            Andy.Assign(Bobby, ChickenMonkey);
            Andy.Assign(Bobby, CoinsToCash);
            Andy.Assign(Noah, ChickenMonkey);
            Jenna.Assign(Noah, Nutshell);
            Jenna.Assign(Will, Nutshell);
            Jenna.Assign(Will, ChickenMonkey);
            Bryan.Assign(Will, StudentExercises);
            Bryan.Assign(Brantley, CoinsToCash);
            Bryan.Assign(Brantley, StudentExercises);

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

            students.Add(Will);
            students.Add(Noah);
            students.Add(Brantley);
            students.Add(Bobby);
            students.Add(Ted);

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

            instructors.Add(Andy);
            instructors.Add(Jenna);
            instructors.Add(Bryan);

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

            exercises.Add(ChickenMonkey);
            exercises.Add(Nutshell);
            exercises.Add(StudentExercises);
            exercises.Add(CoinsToCash);

            Console.WriteLine("- - - - - - - - - - - - - - - - - - - - - - - - -");
            List <Exercise> JSExercises = exercises.Where(exercise => exercise.Langauge == "Javascript").ToList();

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

            List <Student>    c34           = students.Where(student => student.Cohort.Name == "34").ToList();
            List <Instructor> c34I          = instructors.Where(instructor => instructor.Cohort.Name == "34").ToList();
            List <Student>    c35           = students.Where(student => student.Cohort.Name == "35").ToList();
            List <Instructor> c35I          = instructors.Where(instructor => instructor.Cohort.Name == "35").ToList();
            List <Student>    c36           = students.Where(student => student.Cohort.Name == "36").ToList();
            List <Instructor> c36I          = instructors.Where(instructor => instructor.Cohort.Name == "36").ToList();
            List <Student>    LastName      = students.OrderBy(student => student.LastName).ToList();
            List <Student>    NoExercises   = students.Where(student => student.Exercises.Count == 0).ToList();
            List <Student>    MostExercises = students.OrderByDescending(student => student.Exercises.Count).ToList();

            foreach (Student student in c34)
            {
                Console.WriteLine("- - - - - - - - - - - -");
                Console.WriteLine("Cohort 34 Students");
                Console.WriteLine($"{student.FirstName} {student.LastName}");
                Console.WriteLine(c34.Count());
                Console.WriteLine("- - - - - - - - - - - -");
            }
            Console.WriteLine("Cohort 35 Students");
            foreach (Student student in c35)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }
            Console.WriteLine(c35.Count());
            Console.WriteLine("- - - - - - - - - - - -");
            Console.WriteLine("Cohort 36 Students");
            foreach (Student student in c36)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }
            Console.WriteLine(c36.Count());
            Console.WriteLine("- - - - - - - - - - - -");
            Console.WriteLine("Cohort 34 Instructors");
            foreach (Instructor instructor in c34I)
            {
                Console.WriteLine($"{instructor.FirstName} {instructor.LastName}");
            }
            Console.WriteLine("- - - - - - - - - - - -");
            Console.WriteLine("Cohort 35 Instructors");
            foreach (Instructor instructor in c35I)
            {
                Console.WriteLine($"{instructor.FirstName} {instructor.LastName}");
            }
            Console.WriteLine("- - - - - - - - - - - -");
            Console.WriteLine("Cohort 36 Instructors");
            foreach (Instructor instructor in c36I)
            {
                Console.WriteLine($"{instructor.FirstName} {instructor.LastName}");
            }
            Console.WriteLine("- - - - - - - - - - - -");

            Console.WriteLine("Sorted By Last Name");
            foreach (Student student in LastName)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }
            Console.WriteLine("- - - - - - - - - - - -");

            foreach (Student student in NoExercises)
            {
                Console.WriteLine($"No Exercises for {student.FirstName} {student.LastName}");
                Console.WriteLine("- - - - - - - - - - - -");
            }

            Console.WriteLine($"The student with the most exercises is {MostExercises[0].FirstName} {MostExercises[0].LastName}");
            // Console.WriteLine("Report:");
            // foreach (Student student in students)
            // {
            //     foreach (Exercise exercise in student.Exercises)
            //     {
            //         Console.WriteLine($"{student.FirstName} {student.LastName} is working on {exercise.Name}.");
            //     }
            // }
            Console.WriteLine("- - - - - - - - - - - - - - - - - - - - - - - - -");
        }
        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.
             */
            /*
             * Here, you are using the method in Cohort.cs to name a new cohort and create a list of students and instructors associated with the cohort you just named:
             */
            Cohort c29 = new Cohort("Cohort 29");

            Cohort c30 = new Cohort("Cohort 30");

            Cohort c31 = new Cohort("Cohort 31");

            Exercise exercise1 = new Exercise("Celebrity Tribute", "HTML and CSS");
            Exercise exercise2 = new Exercise("Welcome to Nashville", "Javascript");
            Exercise exercise3 = new Exercise("Nutshell", "Javascript");
            Exercise exercise4 = new Exercise("Nutshell", "React");
            Exercise exercise5 = new Exercise("Capstone", "React");
            Exercise exercise6 = new Exercise("LINQ Exercises", "C#");

            Instructor instruct1 = new Instructor("Andy", "Collins", "@andycollins", c29);
            Instructor instruct2 = new Instructor("Steve", "Brownley", "@steve", c30);
            Instructor instruct3 = new Instructor("Jisie", "David", "@jisiedavid", c31);


            Student stu1 = new Student("Hannah", "Neal", "@hannahmneal", c29);
            Student stu2 = new Student("Joel", "Mondesir", "@joelmondesir", c31);
            Student stu3 = new Student("Brian", "Neal", "@brianbneal", c30);


            /*
             * Here, you are creating a list of students and adding the student objects (created above) to it. These student lists will be used with the Instructor type to assign exercises to the students.
             */

            List <Student> studentList29 = new List <Student>()
            {
                stu1
            };

            // AssignExercise is in Instructor.cs; it is a method that adds the Exercise type from Exercise.cs to the Assignment list (type) in Student.cs; i.e., AssignExercise adds a new exercise to the Assignment list for each student object.

            instruct1.AssignExercise(exercise5, stu1);
            instruct1.AssignExercise(exercise6, stu1);

            List <Student> studentList30 = new List <Student>()
            {
                stu3
            };

            instruct2.AssignExercise(exercise4, stu3);
            instruct2.AssignExercise(exercise5, stu3);

            List <Student> studentList31 = new List <Student>()
            {
                stu2
            };

            instruct3.AssignExercise(exercise2, stu2);
            instruct3.AssignExercise(exercise3, stu2);

            List <Student> allStudents = new List <Student>()
            {
                stu1, stu2, stu3
            };

            /*
             * Here, you are creating a list of Exercises and adding the student objects (created above) to it:
             */

            foreach (Student student in allStudents)
            {
                List <string> stuExercises = new List <string>();
                foreach (Exercise stuExercise in student.Assignment)
                {
                    stuExercises.Add(stuExercise.exerciseName);
                }
                Console.WriteLine($"{student.stuFirstName} {student.stuLastName} EXERCISE: {String.Join(", " ,stuExercises)} {student.Cohort.cohortName}");
            }
        }
        static void Main(string[] args)
        {
// Add Exercise
            Exercise CodeyThing = new Exercise();

            CodeyThing.name = "CodeyThing";
            CodeyThing.type = "CSharp";

            Exercise AlmondShell = new Exercise();

            AlmondShell.name = "AlmondShell";
            AlmondShell.type = "JavaScript";

            Exercise BreakBread = new Exercise();

            BreakBread.name = "BreakBread";
            BreakBread.type = "React.js";

            Exercise LaymanTribute = new Exercise();

            LaymanTribute.name = "LaymanTribute";
            LaymanTribute.type = "CSS";

// Adding Cohort

            Cohort ThirtyFour = new Cohort();

            ThirtyFour.name = 34;

            Cohort ThirtyFive = new Cohort();

            ThirtyFive.name = 35;

            Cohort TwentyThree = new Cohort();

            TwentyThree.name = 24;

//Adding Student

            Student Michael = new Student();

            Michael.firstName   = "Michael";
            Michael.lastName    = "Stiles";
            Michael.slackHandle = "mstiles01";
            Michael.Cohort      = 34;

            Student Matt = new Student();

            Michael.firstName   = "Matt";
            Michael.lastName    = "Ross";
            Michael.slackHandle = "mross";
            Michael.Cohort      = 34;

            Student Noah = new Student();

            Michael.firstName   = "Noah";
            Michael.lastName    = "Barfeild";
            Michael.slackHandle = "noahb";
            Michael.Cohort      = 35;

            Student Maggie = new Student();

            Michael.firstName   = "Maggie";
            Michael.lastName    = "Johnson";
            Michael.slackHandle = "mjohn";
            Michael.Cohort      = 24;
        }
Beispiel #8
0
 public Student(string fName, string lastName, string slack, Cohort cohort) :
     base(fName, lastName, slack, cohort)
 {
 }
        static void Main(string[] args)
        {
            Exercise nutshell = new Exercise();

            nutshell.id       = 1;
            nutshell.name     = "nutshell";
            nutshell.language = "Javascript";

            Exercise fitpup = new Exercise();

            fitpup.id       = 2;
            fitpup.name     = "fitpup";
            fitpup.language = "React";

            Exercise dictionaries = new Exercise();

            dictionaries.id       = 3;
            dictionaries.name     = "dictionaries";
            dictionaries.language = "C#";

            Exercise weatherData = new Exercise();

            weatherData.id       = 4;
            weatherData.name     = "Weather Data Challenge";
            weatherData.language = "Javascript";

            Student bobby = new Student();

            bobby.id          = 1;
            bobby.firstName   = "Bobby";
            bobby.lastName    = "Bobby";
            bobby.slackHandle = "Bobbikins";
            bobby.cohort      = 1;


            Student sable = new Student();

            sable.id          = 2;
            sable.firstName   = "Sable";
            sable.lastName    = "Mabel";
            sable.slackHandle = "Sabikins";
            sable.cohort      = 2;

            Student sydney = new Student();

            sydney.id          = 3;
            sydney.firstName   = "Sydney";
            sydney.lastName    = "Sidders";
            sydney.slackHandle = "Siddikins";
            sydney.cohort      = 3;

            Student matt = new Student();

            matt.id          = 4;
            matt.firstName   = "Matt";
            matt.lastName    = "Matt";
            matt.slackHandle = "Mattikins";
            matt.cohort      = 2;

            Cohort one = new Cohort();

            one.id   = 1;
            one.name = "Cohort One";


            Cohort two = new Cohort();

            two.id   = 2;
            two.name = "Cohort Two";

            Cohort three = new Cohort();

            three.id   = 3;
            three.name = "Cohort Three";

            one.students.Add(bobby);
            two.students.Add(sable);
            two.students.Add(matt);
            three.students.Add(sydney);

            Instructor jordan = new Instructor();

            jordan.id           = 2;
            jordan.firstName    = "Jordan";
            jordan.lastName     = "Castelloe";
            jordan.cohortNumber = 1;
            jordan.assignExercise(bobby, nutshell);
            jordan.assignExercise(bobby, weatherData);
            jordan.assignExercise(sable, nutshell);
            jordan.assignExercise(sable, weatherData);
            jordan.assignExercise(matt, nutshell);
            jordan.assignExercise(matt, fitpup);

            Instructor josh = new Instructor();

            josh.id           = 2;
            josh.firstName    = "Josh";
            josh.lastName     = "Rover";
            josh.cohortNumber = 2;
            josh.assignExercise(bobby, weatherData);
            josh.assignExercise(bobby, fitpup);
            josh.assignExercise(sable, fitpup);
            josh.assignExercise(sable, dictionaries);
            josh.assignExercise(matt, fitpup);
            josh.assignExercise(matt, nutshell);

            Instructor kim = new Instructor();

            kim.id           = 3;
            kim.firstName    = "Kim";
            kim.lastName     = "Preece";
            kim.cohortNumber = 3;
            kim.assignExercise(bobby, nutshell);
            kim.assignExercise(bobby, weatherData);
            kim.assignExercise(sable, fitpup);
            kim.assignExercise(sable, nutshell);
            kim.assignExercise(matt, nutshell);
            kim.assignExercise(matt, fitpup);

            one.instructors.Add(jordan);
            two.instructors.Add(josh);
            three.instructors.Add(kim);

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

            students.Add(bobby);
            students.Add(sable);
            students.Add(sydney);
            students.Add(matt);

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

            exercises.Add(nutshell);
            exercises.Add(weatherData);
            exercises.Add(dictionaries);
            exercises.Add(fitpup);

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

            List <Cohort> cohorts = new List <Cohort>()
            {
                one,
                two,
                three
            };

            // foreach(Student student in students){
            //     Console.WriteLine(student.firstName);
            //     foreach(string exercise in student.currentExercises){
            //         Console.WriteLine(exercise);
            //     }
            // }

//         List exercises for the JavaScript language by using the Where() LINQ method.
            IEnumerable <Exercise> JSExercises = exercises.Where(e => e.language == "Javascript");

// List students in a particular cohort by using the Where() LINQ method.
            IEnumerable <Student> cohortOneStudents = students.Where(s => s.cohort == 1);
// List instructors in a particular cohort by using the Where() LINQ method.
            IEnumerable <Instructor> cohortOneInstructors = instructors.Where(i => i.cohortNumber == 1);
// Sort the students by their last name.
            IEnumerable <Student> orderedStudents = students.OrderBy(s => s.lastName);

            orderedStudents.ToList().ForEach(student => Console.WriteLine(student.firstName));
// 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 lazyStudents = students.Where(student => student.currentExercises.Count() == 0);

            lazyStudents.ToList().ForEach(student => Console.WriteLine($"This student is lazy! {student.firstName}"));
// Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            IEnumerable <Student> hardWorkingStudents = students.OrderByDescending(m => m.currentExercises.Count());

            Student hardestWorkingStudent = hardWorkingStudents.First();

//    hardestWorkingStudent.ForEach(student => Console.WriteLine(student));

// How many students in each cohort?
            one.students.Count();
            two.students.Count();
            three.students.Count();
        }
 public Student(string first, string last, string handle, Cohort cohort)
 {
     FirstName   = first;
     LastName    = last;
     SlackHandle = handle;
 }
 public Student(Cohort cohort)
 {
     Cohort    = cohort;
     Exercises = new List <Exercise>();
 }
Beispiel #12
0
        static void Main(string[] args)
        {
            // COHORTS
            Cohort Cohort26 = new Cohort()
            {
                CohortName = "Cohort 26",
            };

            Cohort Cohort27 = new Cohort()
            {
                CohortName = "Cohort 27",
            };

            Cohort Cohort28 = new Cohort()
            {
                CohortName = "Cohort 28",
            };

            // STUDENTS
            Student Daniel = new Student()
            {
                FirstName     = "Daniel",
                LastName      = "Figueroa",
                SlackHandle   = "Daniel Figueroa",
                StudentCohort = Cohort27,
            };
            Student Ricky = new Student()
            {
                FirstName     = "Ricky",
                LastName      = "Bruner",
                SlackHandle   = "Ricky Brunder",
                StudentCohort = Cohort27,
            };
            Student Adelaide = new Student()
            {
                FirstName     = "Adelaide",
                LastName      = "Yoder",
                SlackHandle   = "Adelaide Yoder",
                StudentCohort = Cohort26,
            };
            Student Jennifer = new Student()
            {
                FirstName     = "Jennifer",
                LastName      = "Lawson",
                SlackHandle   = "Jennifer Lawson",
                StudentCohort = Cohort26,
            };
            Student John = new Student()
            {
                FirstName     = "John",
                LastName      = "Wood",
                SlackHandle   = "John Wood",
                StudentCohort = Cohort28,
            };

            // INSTRUCTORS
            Instructor Brenda = new Instructor()
            {
                FirstName        = "Brenda",
                LastName         = "Long",
                SlackHandle      = "Brenda Long",
                InstructorCohort = Cohort27,
            };
            Instructor Jisie = new Instructor()
            {
                FirstName        = "Jisie",
                LastName         = "David",
                SlackHandle      = "Jisie David",
                InstructorCohort = Cohort26,
            };
            Instructor Steve = new Instructor()
            {
                FirstName        = "Steve",
                LastName         = "Brownlee",
                SlackHandle      = "Steve Brownlee",
                InstructorCohort = Cohort27,
            };

            // ExerciseS
            Exercise ExerciseHTML = new Exercise()
            {
                ExerciseName     = "HTML",
                ExerciseLanguage = "HTML"
            };
            Exercise ExerciseSets = new Exercise()
            {
                ExerciseName     = "Sets",
                ExerciseLanguage = "C#"
            };
            Exercise ExerciseDictionaries = new Exercise()
            {
                ExerciseName     = "Dictionaries",
                ExerciseLanguage = "C#"
            };
            Exercise ExerciseNutshell = new Exercise()
            {
                ExerciseName     = "Nutshell",
                ExerciseLanguage = "Javascript"
            };

            // Assigning Excersises to Students
            Brenda.AssignStudent(ExerciseHTML, Daniel);
            Brenda.AssignStudent(ExerciseNutshell, Ricky);
            Brenda.AssignStudent(ExerciseDictionaries, Ricky);

            // For this Exercise, you need to create 4 new List instances to Program.cs: one to contain students, one to contain Exercises, one to contain instructors, and one to contain cohorts.
            List <Student> StudentList = new List <Student>();

            StudentList.Add(Daniel);
            StudentList.Add(Ricky);
            StudentList.Add(Adelaide);
            StudentList.Add(Jennifer);
            StudentList.Add(John);

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

            ExerciseList.Add(ExerciseHTML);
            ExerciseList.Add(ExerciseSets);
            ExerciseList.Add(ExerciseDictionaries);
            ExerciseList.Add(ExerciseNutshell);

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

            InstructorList.Add(Brenda);
            InstructorList.Add(Jisie);
            InstructorList.Add(Steve);

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

            CohortList.Add(Cohort26);
            CohortList.Add(Cohort27);
            CohortList.Add(Cohort28);

            // List exercises for the JavaScript language by using the Where() LINQ method.
            var filteredExercise = ExerciseList.Where(e => e.ExerciseLanguage == "Javascript").ToList();

            foreach (Exercise e in filteredExercise)
            {
                Console.WriteLine($"{e.ExerciseName}");
            }

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

            // List students in a particular cohort by using the Where() LINQ method.
            var filteredStudent = StudentList.Where(s => s.StudentCohort == Cohort27).ToList();

            foreach (Student e in filteredStudent)
            {
                Console.WriteLine($"{e.FirstName} {e.LastName}");
            }

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

            // List instructors in a particular cohort by using the Where() LINQ method.
            var filteredInstructor = InstructorList.Where(s => s.InstructorCohort == Cohort27).ToList();

            foreach (Instructor e in filteredInstructor)
            {
                Console.WriteLine($"{e.FirstName} {e.LastName}");
            }

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

            // Sort the students by their last name.
            var SortedByLastName = StudentList.OrderByDescending(b => b.LastName);

            foreach (Student e in SortedByLastName)
            {
                Console.WriteLine($"{e.FirstName} {e.LastName}");
            }

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

            // Display any students that aren't working on any exercises
            var filteredStudent2 = StudentList.Where(e => e.StudentsExercises.Count() == 0).ToList();

            foreach (Student e in filteredStudent2)
            {
                Console.WriteLine($"{e.FirstName} {e.LastName}");
            }

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

            // Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            var filteredStudent3 = StudentList.OrderByDescending(e => e.StudentsExercises.Count).Take(1);

            foreach (Student e in filteredStudent3)
            {
                Console.Write($"{e.FirstName} {e.LastName}");
            }
            ;
            // Could have also done this
            // var filteredStudent3 = StudentList.OrderByDescending(e => e.StudentsExercises.Count).First();
            // Console.WriteLine($"{filteredStudent3.SlackHandle}");

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

            //How many students in each cohort?
            // var results = from student in StudentList
            // group student.SlackHandle by student.StudentCohort into g
            // select new { Cohort = g.Key, Name = g.ToList() };
            // foreach(var e in results) {
            //     Console.WriteLine($"{e.Cohort.CohortName}: {e.Name}");
            // }
            var results = StudentList.GroupBy(e => e.StudentCohort.CohortName);

            foreach (var item in results)
            {
                Console.WriteLine($"{item.Key} has {item.Count()}");
            }



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

            SqliteConnection db = DatabaseInterface.Connection;

            DatabaseInterface.CheckExerciseTable();

            // Query the database for all the Exercises.
            db.Query <Exercise>(@"SELECT * FROM Exercise")
            .ToList()
            .ForEach(ex => Console.WriteLine($"Exercise: {ex.ExerciseName}, written in {ex.ExerciseLanguage}"));

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

            // Find all the exercises in the database where the language is JavaScript.
            db.Query <Exercise>(@"SELECT * FROM Exercise")
            .Where(ex => ex.ExerciseLanguage == "Javascript")
            .ToList()
            .ForEach(ex => Console.WriteLine($"Exercise: {ex.ExerciseName}, written in {ex.ExerciseLanguage}"));

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

            // Insert a new exercise into the database.
            // db.Execute(@"
            //     INSERT INTO Exercise (ExerciseName, ExerciseLanguage)
            //     VALUES ('Map', 'Javascript')");
            // db.Query<Exercise>(@"SELECT * FROM Exercise")
            // .Where(ex => ex.ExerciseLanguage == "Javascript")
            // .ToList()
            // .ForEach(ex => Console.WriteLine($"Exercise: {ex.ExerciseName}, written in {ex.ExerciseLanguage}"));

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

            // Find all instructors in the database. Include each instructor's cohort.
            IEnumerable <Instructor> instructor2 = db.Query <Instructor, Cohort, Instructor>(@"
            SELECT 
                i.Id,
                i.FirstName,
                i.LastName,
                i.SlackHandle,
                i.InstructorCohortId,
                c.Id,
                c.CohortName
            FROM Instructor i
            JOIN Cohort c ON c.Id = i.InstructorCohortId", (instructor, cohort) => {
                instructor.InstructorCohort = cohort;
                return(instructor);
            });

            foreach (Instructor ins in instructor2)
            {
                Console.WriteLine($"{ins.FirstName} {ins.LastName} teaches {ins.InstructorCohort.CohortName}");
            }

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

            // Insert a new instructor into the database. Assign the instructor to an existing cohort.
            // db.Execute(@"
            //     INSERT INTO Instructor (FirstName, LastName, SlackHandle, InstructorCohortId)
            //     VALUES ('Andy', 'Collins', 'Andy Collins', 2)");
            db.Query <Instructor, Cohort, Instructor>(@"
            SELECT 
                i.Id,
                i.FirstName,
                i.LastName,
                i.SlackHandle,
                i.InstructorCohortId,
                c.Id,
                c.CohortName
            FROM Instructor i
            JOIN Cohort c ON c.Id = i.InstructorCohortId", (instructor, cohort) => {
                instructor.InstructorCohort = cohort;
                return(instructor);
            }).ToList().ForEach(ins => Console.WriteLine($"{ins.FirstName} {ins.LastName} teaches {ins.InstructorCohort.CohortName}"));

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

            // Assign an existing exercise to an existing student.
            DatabaseInterface.CheckAssignedExerciseTable();
            // db.Execute(@"
            //     INSERT INTO AssignedExercise (StudentId, ExerciseId)
            //     VALUES ('2', '2');
            // ");

            // Challenge - Find all the students in the database. Include each student's cohort AND each student's list of exercises.
            Dictionary <Student, List <Exercise> > CulminatedExercise = new Dictionary <Student, List <Exercise> >();

            db.Query <Student, Cohort, Exercise, Student>(@"
            SELECT 
                s.Id,
                s.FirstName,
                s.LastName,
                s.SlackHandle,
                s.StudentCohortId,
                c.Id,
                c.CohortName,
                e.Id,
                e.ExerciseName,
                e.ExerciseLanguage
            FROM Student s
            JOIN AssignedExercise ae ON ae.StudentId = s.Id
            JOIN Cohort c ON c.Id = s.StudentCohortId
            JOIN Exercise e ON e.Id = ae.ExerciseId", (student, cohort, exercise) => {
                if (!CulminatedExercise.ContainsKey(student))
                {
                    student.StudentCohort       = cohort;
                    CulminatedExercise[student] = new List <Exercise>();
                }
                CulminatedExercise[student].Add(exercise);
                return(student);
            });

            foreach (KeyValuePair <Student, List <Exercise> > ex in CulminatedExercise)
            {
                Console.WriteLine($"{ex.Key.SlackHandle} is in {ex.Key.StudentCohort.CohortName} and is working:");
                foreach (Exercise item in ex.Value)
                {
                    Console.WriteLine($"{item.ExerciseName}  written in {item.ExerciseLanguage}");
                }
            }
        }
        static void Main(string[] args)
        {
            // Create 4, or more, exercises.
            Exercise Nutshell        = new Exercise("Nutshell", "React");
            Exercise HolidayRoad     = new Exercise("Holiday Road", "Vanilla Javascript");
            Exercise BankHeist       = new Exercise("Bank Heist", "C#");
            Exercise MartinsAquarium = new Exercise("Martin's Aquarium", "Vanilla Javascript");
            // Create 3, or more, cohorts.
            Cohort Evening10 = new Cohort("Evening Cohort 10");
            Cohort Day37     = new Cohort("Day Cohort 37");
            Cohort Data8     = new Cohort("Data Analytics Cohort 8");

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

            Student James   = new Student("James", "Nitz", "_jamesClimb", "Day Cohort 37");
            Student Willy   = new Student("Willy", "Metcalf", "_willyRaves", "Data Analytics Cohort 8");
            Student William = new Student("William", "Green", "_williamPizza", "Evening Cohort 10");
            Student Audrey  = new Student("Audrey", "Borgra", "_audreyCodes", "Day Cohort 37");

            Evening10.AddStudent(William);
            Day37.AddStudent(James);
            Day37.AddStudent(Audrey);
            Data8.AddStudent(Willy);
            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor Mo     = new Instructor("Mo", "Silvera", "_moMoney", "Day Cohort 37", "Being Awesome");
            Instructor Brenda = new Instructor("Brenda", "Long", "_brendaBreaksDownCode", "Data Analytics Cohort 8", "Designing websites");
            Instructor Steve  = new Instructor("Steve", "Brownlee", "_steveChoortlehort", "Evening Cohort 10", "Dad Jokes");

            Day37.AddInstructor(Mo);
            Data8.AddInstructor(Brenda);
            // Have each instructor assign 2 exercises to each of the students.
            Mo.AddExercise(James, Nutshell);
            Mo.AddExercise(James, MartinsAquarium);
            Mo.AddExercise(Audrey, Nutshell);
            Mo.AddExercise(Audrey, MartinsAquarium);

            Brenda.AddExercise(Willy, BankHeist);
            Brenda.AddExercise(Willy, HolidayRoad);

            Steve.AddExercise(William, Nutshell);
            Steve.AddExercise(William, HolidayRoad);

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

            students.Add(James);
            students.Add(Willy);
            students.Add(William);
            students.Add(Audrey);

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

            exercises.Add(Nutshell);
            exercises.Add(HolidayRoad);
            exercises.Add(MartinsAquarium);
            exercises.Add(BankHeist);

            foreach (Exercise exercise in exercises)
            {
                Console.WriteLine($"{exercise.ExerciseName}");
                // loops student
                foreach (Student student in students)
                {
                    // loops exercise collection and then conditional
                    //   student.ExerciseCollection list of exercise which is a class
                    foreach (Exercise studentExercise in student.ExerciseCollection)
                    {
                        if (studentExercise == exercise)
                        {
                            Console.WriteLine($"{student.FirstName} {student.LastName}");
                        }
                    }
                }
                Console.WriteLine($"---------------------------------------------------");
            }
        }
        static void Main(string[] args)
        {
            List <Student>  allStudents  = new List <Student>();
            List <Exercise> allExercises = new List <Exercise>();

            Cohort cohort1 = new Cohort("Cohort 1");
            Cohort cohort2 = new Cohort("Cohort 2");
            Cohort cohort3 = new Cohort("Cohort 3");

            Exercise excercise1 = new Exercise(allExercises)
            {
                Name = "excercise1", Language = "C#"
            };
            Exercise excercise2 = new Exercise(allExercises)
            {
                Name = "excercise2", Language = "Js"
            };
            Exercise excercise3 = new Exercise(allExercises)
            {
                Name = "excercise3", Language = "C#"
            };
            Exercise excercise4 = new Exercise(allExercises)
            {
                Name = "excercise4", Language = "Js"
            };
            Exercise excercise5 = new Exercise(allExercises)
            {
                Name = "excercise5", Language = "C#"
            };
            Exercise excercise6 = new Exercise(allExercises)
            {
                Name = "excercise6", Language = "CSS"
            };

            //use method to add to cohort list and link cohort to student/teacher

            Student student1 = cohort1.AddNewStudent("Steve", "Stevens", "SoS");
            Student student2 = cohort1.AddNewStudent("Beve", "Bevens", "BoB");
            Student student3 = cohort2.AddNewStudent("Fleve", "Flevens", "FoF");
            Student student4 = cohort2.AddNewStudent("Creve", "Crevens", "CoC");
            Student student5 = cohort3.AddNewStudent("Shmeve", "Shmevens", "ShOSh");
            Student student6 = cohort3.AddNewStudent("Dreve", "Drevens", "DoD");
            // cohort1.AddNewInstructor("Zeve", "Zevens", "ZoZ", "C#");
            // cohort1.AddNewInstructor("Heve", "Hevens", "HoH", "C#");
            // cohort1.AddNewInstructor("Leve", "Levens", "LoL", "C#");

            Instructor instructor1 = cohort1.AddNewInstructor("Zeve", "Zevens", "ZoZ", "C#");
            Instructor instructor2 = cohort1.AddNewInstructor("Heve", "Hevens", "HoH", "C#");
            Instructor instructor3 = cohort1.AddNewInstructor("Leve", "Levens", "LoL", "C#");



            //each instructor assigns to methods to a student.

            instructor1.AssignExercise(excercise1, cohort1);
            instructor1.AssignExercise(excercise2, cohort1);
            instructor2.AssignExercise(excercise1, cohort2);
            instructor2.AssignExercise(excercise2, cohort2);
            instructor3.AssignExercise(excercise1, cohort3);
            instructor3.AssignExercise(excercise2, cohort3);
        }
Beispiel #15
0
        static void Main(string[] args)
        {
//********** STUDENT EXERCISES - PART 1 ********** */
            Console.WriteLine(" ");
            Console.WriteLine("  ********** STUDENT EXERCISES - PART 1  ********** ");

// Create 4, or more, exercises.
            Exercise PracticeLists   = new Exercise("Practice Lists", "C#");
            Exercise PracticeDict    = new Exercise("Practice Dictionaries", "C#");
            Exercise PracticeMap     = new Exercise("Practice Mapping", "JavaScript");
            Exercise PracticeRoutes  = new Exercise("Practice Routing", "React");
            Exercise ChallengeMap    = new Exercise("Challenge Mapping", "JavaScript");
            Exercise ChallengeRoutes = new Exercise("Challenge Routing", "React");
            Exercise ChallengeLists  = new Exercise("Challenge Lists", "C#");
            Exercise ChallengeDict   = new Exercise("Challenge Dict", "C#");
            Exercise OverlyExcited   = new Exercise("Overly Excited", "JavaScript");
            Exercise SolarSystem     = new Exercise("SolarSystem", "C#");
            Exercise CarLot          = new Exercise("CarLot", "React");
            Exercise DynamicCards    = new Exercise("DynamicCards", "JavaScript");

// Create 3, or more, cohorts.
            Cohort Cohort28 = new Cohort("Cohort 28");
            Cohort Cohort29 = new Cohort("Cohort 29");
            Cohort Cohort30 = new Cohort("Cohort 30");

// Create 4, or more, students and assign them to one of the cohorts.
            Student TomSmith      = new Student("Tom", "Smith", "TomSmith@slack", "Cohort28");
            Student DickSmith     = new Student("Dick", "Smith", "DickSmith@slack", "Cohort28");
            Student HarrySmith    = new Student("Harry", "Smith", "HarrySmith@slack", "Cohort29");
            Student JaneSmith     = new Student("Jane", "Smith", "JaneSmith@slack", "Cohort 29");
            Student LarrySmith    = new Student("Larry", "Smith", "LarrySmith@slack", "Cohort29");
            Student KristinSmith  = new Student("Kristin", "Smith", "KristinSmith@slack", "Cohort30");
            Student LoshannaSmith = new Student("Loshanna", "Smith", "LoshannaSmith@slack", "Cohort30");
            Student TreSmith      = new Student("Tre", "Smith", "TreSmith@slack", "Cohort28");

            Cohort28.CohortStudentList.Add(TomSmith);
            Cohort28.CohortStudentList.Add(DickSmith);
            Cohort29.CohortStudentList.Add(HarrySmith);
            Cohort29.CohortStudentList.Add(JaneSmith);
            Cohort29.CohortStudentList.Add(LarrySmith);
            Cohort30.CohortStudentList.Add(KristinSmith);
            Cohort30.CohortStudentList.Add(LoshannaSmith);
            Cohort28.CohortStudentList.Add(TreSmith);

// Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor JisieDavid   = new Instructor("Jisie", "David", "JisieDavid@slack", "Cohort30");
            Instructor AndyCollins  = new Instructor("Andy", "Collins", "AndyCollins@slack", "Cohort29");
            Instructor LeahHoefling = new Instructor("Leah", "Hoefling", "LeahHoefling@slack", "Cohort29");

            Cohort30.CohortInstructorList.Add(JisieDavid);
            Cohort29.CohortInstructorList.Add(AndyCollins);
            Cohort29.CohortInstructorList.Add(LeahHoefling);

// Have each instructor assign 2 exercises to each of the students.
            JisieDavid.AssignExercise(ChallengeLists, TomSmith);
            JisieDavid.AssignExercise(PracticeLists, DickSmith);
            JisieDavid.AssignExercise(PracticeLists, HarrySmith);
            JisieDavid.AssignExercise(PracticeLists, JaneSmith);
            JisieDavid.AssignExercise(PracticeDict, TomSmith);
            JisieDavid.AssignExercise(PracticeDict, DickSmith);
            JisieDavid.AssignExercise(PracticeDict, HarrySmith);
            JisieDavid.AssignExercise(PracticeDict, JaneSmith);

            AndyCollins.AssignExercise(PracticeMap, TomSmith);
            AndyCollins.AssignExercise(PracticeMap, DickSmith);
            AndyCollins.AssignExercise(PracticeMap, HarrySmith);
            AndyCollins.AssignExercise(PracticeMap, JaneSmith);
            AndyCollins.AssignExercise(PracticeRoutes, TomSmith);
            AndyCollins.AssignExercise(PracticeRoutes, DickSmith);
            AndyCollins.AssignExercise(PracticeRoutes, TomSmith);
            AndyCollins.AssignExercise(PracticeRoutes, JaneSmith);

            LeahHoefling.AssignExercise(ChallengeMap, TomSmith);
            LeahHoefling.AssignExercise(ChallengeDict, DickSmith);
            LeahHoefling.AssignExercise(ChallengeMap, HarrySmith);
            LeahHoefling.AssignExercise(ChallengeMap, JaneSmith);
            LeahHoefling.AssignExercise(ChallengeRoutes, TomSmith);
            LeahHoefling.AssignExercise(ChallengeRoutes, DickSmith);
            LeahHoefling.AssignExercise(ChallengeRoutes, HarrySmith);
            LeahHoefling.AssignExercise(ChallengeRoutes, TomSmith);

            // This has to be an Instructor.cs method because no other way to indicate instructor
            // when passing type and argument
            // public void AssignExercise(Exercise exercise, Student student) {
            //     student.Exercises.Add(exercise);
            //     ie: JaneSmith.Exercises.Add(ChallengeRoutes);
            // }

// Create a list of students. Add all of the student instances to it.
            List <Student> students = new List <Student>()
            {
                TomSmith,
                DickSmith,
                HarrySmith,
                JaneSmith,
                LarrySmith,
                KristinSmith,
                LoshannaSmith,
                TreSmith
            };
// Create a list of exercises. Add all of the exercise instances to it.
            List <Exercise> exercises = new List <Exercise>()
            {
                PracticeLists,
                PracticeDict,
                PracticeMap,
                PracticeRoutes,
                ChallengeMap,
                ChallengeRoutes,
                OverlyExcited,
                SolarSystem,
                CarLot,
                DynamicCards
            };

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

            foreach (Student studentRecord in students)
            {
                List <string> oneStudentsExercises = new List <string>();

                foreach (Exercise oneStudentsExercise in studentRecord.TheStudentsExerciseList)
                {
                    oneStudentsExercises.Add(oneStudentsExercise.ExerciseName);
                }

                string exerciseListString = string.Join(", ", oneStudentsExercises);
                Console.WriteLine(" ");
                Console.WriteLine($"***** Exercises for: {studentRecord.StudentFirstName}{studentRecord.StudentLastName} *****");
                Console.WriteLine($"{exerciseListString}");
            }


//********** STUDENT EXERCISES - PART 2 ********** */
//     Assigning Student Exercises with LINQ

            List <Cohort> cohorts = new List <Cohort>()
            {
                Cohort28,
                Cohort29,
                Cohort30
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                JisieDavid,
                AndyCollins,
                LeahHoefling
            };

            Console.WriteLine("Cohort 28");
            Cohort28.ListInstructors();
            Cohort28.ListStudents();
            Console.WriteLine(" ");
            Console.WriteLine("Cohort 29");
            Cohort29.ListInstructors();
            Cohort29.ListStudents();
            Console.WriteLine(" ");
            Console.WriteLine("Cohort 30");
            Cohort30.ListInstructors();
            Cohort30.ListStudents();
            Console.WriteLine(" ");


// Same for instructors and cohorts
// List exercises for the JavaScript language by using the Where() LINQ method.
            Console.WriteLine(" ");
            Console.WriteLine(" ");
            Console.WriteLine("  ********** STUDENT EXERCISES - PART 2 ********** ");
            Console.WriteLine(" ");
            Console.WriteLine(" ** Exercises in JavaScript **");

// QUERY Syntax - List<Exercise> JSEcercises = ExerciseList.Where(exercises => exercises.Language).ToList();
// I used METHOD SYNTAX
            var exercisesList = from exercise in exercises
                                where exercise.Language == "JavaScript"
                                select exercise;

            foreach (Exercise j in exercisesList)
            {
                Console.WriteLine($"     {j.ExerciseName}");
            }
            ;

// List students in a particular cohort by using the Where() LINQ method.
            Console.WriteLine(" ");
            Console.WriteLine(" ** Students in Cohort 28 **");
            var cohort28List = from student in students
                               where student.CohortName == "Cohort28"
                               select student;

            foreach (Student s in cohort28List)
            {
                Console.WriteLine($"     {s.StudentFirstName} {s.StudentLastName}");
            }
            ;

// List instructors in a particular cohort by using the Where() LINQ method.
            Console.WriteLine(" ");
            Console.WriteLine(" ** Instructor(s) in Cohort 29 **");
            var cohort29List = from instructor in instructors
                               where instructor.CohortName == "Cohort29"
                               select instructor;

            foreach (Instructor item in cohort29List)
            {
                Console.WriteLine($"     {item.InstructorFirstName} {item.InstructorLastName}");
            }
            ;

// Sort the students by their last name.
            Console.WriteLine(" ");
            Console.WriteLine(" ** Students sorted by first name **");
            var studentLastNameSort = from student in students
                                      orderby student.StudentFirstName
                                      select student;

            foreach (Student s in studentLastNameSort)
            {
                Console.WriteLine($"     {s.StudentFirstName} {s.StudentLastName}");
            }
            ;

// Display any students that aren't working on any exercises
// (Make sure one of your student instances don't have any exercises.
            Console.WriteLine(" ");
            Console.WriteLine(" ** Students not working on exercises **");
            var studentNotWorkingList = from student in students
                                        where student.TheStudentsExerciseList.Count == 0
                                        select student;

            foreach (Student s in studentNotWorkingList)
            {
                Console.WriteLine($"     {s.StudentFirstName} {s.StudentLastName}");
            }
            ;

// Which student is working on the most exercises?
// Make sure one of your students has more exercises than the others.
            Console.WriteLine(" ");
            Console.WriteLine(" ** Student working on the most exercises **");
            var studentMostWorking = from student in students
                                     orderby student.TheStudentsExerciseList.Count descending
                                     select student;

            Console.WriteLine($"     {students[0].StudentFirstName} {students[0].StudentLastName} is working on the most exercises");

            foreach (Student s in studentMostWorking)
            {
                Console.WriteLine($"     {s.StudentFirstName} {s.StudentLastName} {s.TheStudentsExerciseList.Count}");
            }
            ;
            // @nd Step - Student StudentWithTheMostExercises = StudentMost Working.First();

// How many students in each cohort?
            Console.WriteLine(" ");
            Console.WriteLine(" ** How many students in each cohort **");

            foreach (Cohort c in cohorts)
            {
                var studentsPerCohort = c.CohortStudentList.Count;
                Console.WriteLine($"   There are {c.CohortStudentList.Count} students in {c.CohortName} ");
            }
            ;
            // List<CohortReport> CohortReportList = (from stu in StudentList
            // group stu by stu.Cohort.Name into groupedStu
            // Select new CohortReport()
            // {
            // CohortName = groupedStu.Key
            // StudentCount = groupedStu.Count()
            //   }).ToList
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            //create exercises
            Exercise lists         = new Exercise(1, "Lists", "C#");
            Exercise classes       = new Exercise(2, "Classes", "C#");
            Exercise dictionaries  = new Exercise(3, "Dictionaries", "C#");
            Exercise dailyJournal  = new Exercise(4, "Daily Journal", "JavaScript");
            Exercise chickenMonkey = new Exercise(5, "Chicken Monkey", "JavaScript");

            //add exercises to list
            List <Exercise> exercises = new List <Exercise>()
            {
                lists, classes, dictionaries, dailyJournal, chickenMonkey
            };

            //create cohorts
            Cohort c31 = new Cohort(31, "C31");
            Cohort c32 = new Cohort(32, "C32");
            Cohort c33 = new Cohort(33, "C33");

            //add cohorts to list
            List <Cohort> cohorts = new List <Cohort>()
            {
                c31, c32, c33
            };


            //create students
            Student juan  = new Student(1, "Juan", "Solo", "juan.solo", 31);
            Student ken   = new Student(2, "Ken", "M", "ken.m", 32);
            Student mike  = new Student(3, "Mike", "Jones", "mike.jones", 33);
            Student billy = new Student(4, "Billy", "Mays", "billy.mays", 31);
            Student tom   = new Student(5, "Tom", "Foolery", "tom", 31);

            //add students to list
            List <Student> students = new List <Student>()
            {
                juan, ken, mike, billy, tom
            };

            //create instructors
            Instructor andy  = new Instructor(1, "Andy", "Collins", "andy.collins", "Jokes", 31);
            Instructor jisie = new Instructor(2, "Jisie", "David", "jisie", "Sneaking up on people in a boot.", 33);
            Instructor joe   = new Instructor(3, "Joe", "Sheppard", "joe.shep", "Dad Jokes", 32);

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

            //add students to cohort
            c31.StudentList.Add(juan);
            c31.StudentList.Add(ken);
            c31.StudentList.Add(mike);
            c31.StudentList.Add(billy);
            c32.StudentList.Add(tom);

            //assign instructors to a cohort
            c31.InstructorList.Add(andy);
            c31.InstructorList.Add(jisie);
            c31.InstructorList.Add(joe);

            //assign exercises to students
            andy.AssignExercise(juan, lists);
            andy.AssignExercise(juan, classes);
            andy.AssignExercise(billy, dictionaries);
            andy.AssignExercise(ken, lists);
            andy.AssignExercise(ken, dailyJournal);
            andy.AssignExercise(mike, dailyJournal);
            andy.AssignExercise(billy, classes);
            andy.AssignExercise(mike, dictionaries);

            jisie.AssignExercise(mike, lists);
            jisie.AssignExercise(ken, classes);
            jisie.AssignExercise(juan, dictionaries);
            jisie.AssignExercise(ken, lists);
            jisie.AssignExercise(juan, dailyJournal);
            jisie.AssignExercise(mike, dailyJournal);
            jisie.AssignExercise(billy, classes);
            jisie.AssignExercise(mike, dictionaries);

            joe.AssignExercise(juan, lists);
            joe.AssignExercise(juan, classes);
            joe.AssignExercise(billy, dictionaries);
            joe.AssignExercise(ken, lists);
            joe.AssignExercise(ken, dailyJournal);
            joe.AssignExercise(mike, dailyJournal);
            joe.AssignExercise(billy, classes);
            joe.AssignExercise(mike, dictionaries);

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

            Console.WriteLine("The following exercises use JavaScript:");

            foreach (Exercise ex in jsExercises)
            {
                Console.WriteLine($"{ex.Id}. {ex.ExerciseName}");
            }
            Console.WriteLine();

            //2. List students in a particular cohort by using the Where() LINQ method.
            IEnumerable <Student> chrt31Students =
                from student in students
                where student.CohortId is 31
                select student;

            Console.WriteLine("The following students are in Cohort 31:");

            foreach (Student c in chrt31Students)
            {
                Console.WriteLine($"{c.FirstName} {c.LastName}");
            }
            Console.WriteLine();

            //3. List instructors in a particular cohort by using the Where() LINQ method.
            IEnumerable <Instructor> c31Instructor =
                from instructor in instructors
                where instructor.CohortId is 31
                select instructor;

            Console.WriteLine("The following instructor(s) is/are leading Cohort 31:");

            foreach (Instructor i in c31Instructor)
            {
                Console.WriteLine($"{i.FirstName} {i.LastName}");
            }
            Console.WriteLine();

            //4. Sort the students by their last name.
            IEnumerable <Student> stuLastNames =
                from student in students
                orderby student.LastName descending
                select student;

            Console.WriteLine("This list orders students by last name descending:");
            foreach (Student stu in stuLastNames)
            {
                Console.WriteLine($"{stu.LastName} {stu.FirstName}");
            }
            Console.WriteLine();

            //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> stuWithNoExercises =
                from ex in students
                where ex.ExerciseList.Count() == 0
                select ex;

            Console.WriteLine("The following students are not currently working on any exercises:");
            foreach (Student ex in stuWithNoExercises)
            {
                Console.WriteLine($"{ex.FirstName} {ex.LastName}");
            }
            Console.WriteLine();

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

            Console.WriteLine("The student with the most exercises is:");
            Console.WriteLine($"{mostEx.FirstName} {mostEx.LastName}");
            Console.WriteLine();

            //Create a report of all the exercises students are currently working on.
            foreach (Student stu in students)
            {
                Console.WriteLine();
                Console.WriteLine($"{stu.FirstName} {stu.LastName} is currently working on:");
                foreach (Exercise stuEx in stu.ExerciseList)
                {
                    Console.WriteLine($"{stuEx.ExerciseName}");
                }
            }

            //7. How many students in each cohort?
            Console.WriteLine();
            Console.WriteLine("Count the number of students in each cohort");
            foreach (Cohort stu in cohorts)
            {
                Console.WriteLine($"{stu.CohortName} has {stu.StudentList.Count()} students");
            }
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            Student emily = new Student()
            {
                FirstName    = "Emily",
                LastName     = "Taylor",
                SlackHandle  = "EmilyFromSpringfield",
                CohortNumber = 50
            };

            Student suzanne = new Student()
            {
                FirstName    = "Suzanne",
                LastName     = "Taylor",
                SlackHandle  = "SuzanneFromSpringfield",
                CohortNumber = 50
            };

            Student eric = new Student()
            {
                FirstName    = "Eric",
                LastName     = "Taylor",
                SlackHandle  = "EricFromSpringfield",
                CohortNumber = 50
            };

            Student pete = new Student()
            {
                FirstName    = "Pete",
                LastName     = "Jenkins",
                SlackHandle  = "EricFromSpringfield",
                CohortNumber = 34
            };

            Cohort c34 = new Cohort()
            {
                Number = 34,
            };

            Cohort c50 = new Cohort()
            {
                Number = 50,
            };

            Cohort c55 = new Cohort()
            {
                Number = 55,
            };

            Instructor blanche = new Instructor()
            {
                FirstName    = "Blanche",
                LastName     = "Devereaux",
                SlackHandle  = "IGotBD",
                Specialty    = "Wink Wink Nudge Nudge",
                CohortNumber = 50
            };

            Instructor rose = new Instructor()
            {
                FirstName    = "Rose",
                LastName     = "Nylund",
                SlackHandle  = "IWearDresses",
                Specialty    = "Stories About Home",
                CohortNumber = 55
            };

            Instructor dorothy = new Instructor()
            {
                FirstName    = "Dorothy",
                LastName     = "Syspornack",
                SlackHandle  = "LiteratureLady42",
                Specialty    = "Subbin'",
                CohortNumber = 50
            };

            Instructor sofia = new Instructor()
            {
                FirstName    = "Sofia",
                LastName     = "Petrillo",
                SlackHandle  = "BlackPurseShorty",
                Specialty    = "Quips",
                CohortNumber = 50
            };

            Exercise ternary = new Exercise()
            {
                Name     = "Ternary Traveler",
                Language = "JavaScript",
            };
            Exercise trestlebridge = new Exercise()
            {
                Name     = "Trestlebridge Farm",
                Language = "C#",
            };
            Exercise nashville = new Exercise()
            {
                Name     = "Welcome To Nashville",
                Language = "JavaScript",
            };
            Exercise nutshell = new Exercise()
            {
                Name     = "Nutshell",
                Language = "React",
            };


            sofia.AssignExercise(emily.FirstName, nutshell.Name);
            sofia.AssignExercise(suzanne.FirstName, trestlebridge.Name);
            dorothy.AssignExercise(eric.FirstName, nutshell.Name);
            dorothy.AssignExercise(pete.FirstName, nashville.Name);
            rose.AssignExercise(eric.FirstName, nutshell.Name);
            rose.AssignExercise(suzanne.FirstName, nutshell.Name);
            blanche.AssignExercise(emily.FirstName, ternary.Name);
            blanche.AssignExercise(eric.FirstName, ternary.Name);

            List <Student> students = new List <Student>()
            {
                emily,
                suzanne,
                eric,
                pete,
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                ternary,
                trestlebridge,
                nashville,
                nutshell
            };



            List <Instructor> instructors = new List <Instructor>()
            {
                blanche,
                rose,
                dorothy,
                sofia
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                c34,
                c50,
                c55
            };

            IEnumerable <Exercise> JsExercises = exercises
                                                 .Where(e => e.Language == ("JavaScript"));

            foreach (Exercise e in JsExercises)
            {
                Console.WriteLine($"{e.Name} contains {e.Language}");
            }

            IEnumerable <Student> StudentCohorts = students
                                                   .Where(s => s.FirstName == s.FirstName);

            foreach (Student s in StudentCohorts)
            {
                Console.WriteLine($"{s.FirstName} is in Cohort {s.CohortNumber}");
            }

            IEnumerable <Instructor> InstructorCohorts = instructors
                                                         .Where(i => i.FirstName == i.FirstName);

            foreach (Instructor i in InstructorCohorts)
            {
                Console.WriteLine($"{i.FirstName} is in Cohort {i.CohortNumber}");
            }

            var sortByStudentLastName = students.OrderBy(s => s);

            foreach (Student s in sortByStudentLastName)
            {
                Console.WriteLine(s.LastName);
            }


            Console.WriteLine($"{sofia.FirstName} done assigned {emily.FirstName} the {nutshell.Name}");
            Console.WriteLine($"{sofia.FirstName} also assigned {suzanne.FirstName} something, but hers is {trestlebridge.Name}");
            Console.WriteLine($"{dorothy.FirstName} assigned {eric.FirstName} {nutshell.Name}");
            Console.WriteLine($"{dorothy.FirstName} also assigned {pete.FirstName} something, but it is {nashville.Name}");
            Console.WriteLine($"{rose.FirstName} assigned {eric.FirstName}  {nutshell.Name}");
            Console.WriteLine($"{rose.FirstName} also assigned {suzanne.FirstName} something, but it is {nutshell.Name}");
            Console.WriteLine($"{blanche.FirstName}  assigned {emily.FirstName} {ternary.Name}");
            Console.WriteLine($"{blanche.FirstName} also assigned {eric.FirstName} something, but it is {ternary.Name}");
            Console.WriteLine($"My ladies are {emily.FirstName} {emily.LastName} & {suzanne.FirstName} {suzanne.LastName}");
        }
Beispiel #18
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 exercises
            Exercise chickenMonkey    = new Exercise("Chicken Monkey", "JavaScript");
            Exercise fizzBuzz         = new Exercise("FizzBuzz", "JavaScript");
            Exercise dailyJournal     = new Exercise("Daily Journal", "JavaScript");
            Exercise frontEndCapstone = new Exercise("Front End Capstone", "JavaScript");
            Exercise urbanPlanner     = new Exercise("Urban Planner", "C#");
            Exercise englishIdioms    = new Exercise("English Idioms", "C#");

            // Create cohorts
            Cohort day34 = new Cohort("Day Cohort 34");
            Cohort day33 = new Cohort("Day Cohort 33");
            Cohort day35 = new Cohort("Day Cohort 35");

            // Create students
            Student joe    = new Student("Joe", "Snyder", "Joe Snyder", day34);
            Student brian  = new Student("Brian", "Wilson", "Brian Wilson", day34);
            Student curtis = new Student("Curtis", "Crutchfield", "Curtis Crutchfield", day34);
            Student allie  = new Student("Allie", "Patton", "Allison Patton", day34);
            Student george = new Student("George", "Kelley", "George Kelley", day35);
            Student taylor = new Student("Taylor", "Carroll", "Taylor Carroll", day35);
            Student alex   = new Student("Alex", "Rumsey", "Alex Rumsey", day33);

            // Assign students to their respective cohorts
            day34.Students.Add(joe);
            day34.Students.Add(brian);
            day34.Students.Add(curtis);
            day34.Students.Add(allie);
            day35.Students.Add(george);
            day35.Students.Add(taylor);
            day33.Students.Add(alex);

            // Create instructors
            Instructor andy  = new Instructor("Andy", "Collins", "Andy C", day34, "C#");
            Instructor bryan = new Instructor("Bryan", "Nilsen", "Bryan N", day33, "High fives");
            Instructor steve = new Instructor("Steve", "Brownlee", "Steve B", day35, "Dad jokes");

            // Assign instructors to their respective cohorts
            day34.Instructors.Add(andy);
            day33.Instructors.Add(bryan);
            day35.Instructors.Add(steve);

            foreach (Instructor instructor in day34.Instructors)
            {
                foreach (Student student in day34.Students)
                {
                    instructor.AssignExercise(chickenMonkey, student);
                    instructor.AssignExercise(fizzBuzz, student);
                }
            }

            foreach (Instructor instructor in day33.Instructors)
            {
                foreach (Student student in day33.Students)
                {
                    instructor.AssignExercise(dailyJournal, student);
                    instructor.AssignExercise(frontEndCapstone, student);
                }
            }

            foreach (Instructor instructor in day35.Instructors)
            {
                foreach (Student student in day35.Students)
                {
                    instructor.AssignExercise(urbanPlanner, student);
                    instructor.AssignExercise(englishIdioms, student);
                }
            }

            // Assign extra exercises to one student
            andy.AssignExercise(urbanPlanner, brian);

            // Create master lists for all cohorts, exercises, students, and instructors
            List <Cohort> allCohorts = new List <Cohort>()
            {
                day33, day34, day35
            };

            List <Exercise> allExercises = new List <Exercise>()
            {
                chickenMonkey, fizzBuzz, dailyJournal, frontEndCapstone, urbanPlanner, englishIdioms
            };

            List <Student> allStudents = new List <Student>()
            {
                joe, brian, curtis, allie, george, taylor, alex
            };

            List <Instructor> allInstructors = new List <Instructor>()
            {
                andy, bryan, steve
            };

            // Generate a report that displays which students are working on which exercises
            foreach (Exercise exercise in allExercises)
            {
                // Console.WriteLine($"----- {exercise.Name} ----- ");
                foreach (Cohort cohort in allCohorts)
                {
                    foreach (Student student in cohort.Students)
                    {
                        if (student.Exercises.Contains(exercise))
                        {
                            // Console.WriteLine($"{student.FirstName} {student.LastName}, ");
                        }
                    }
                }
            }

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

            // Print out all the javascript exercises
            foreach (Exercise exercise in javascriptExercise)
            {
                // Console.WriteLine($"{exercise.Name}: {exercise.Language}");
            }

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

            // Print out all the students in cohort 34
            // Console.WriteLine("===== Cohort 34 Students =====");
            foreach (Student student in cohort34Students)
            {
                // Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            // List instructors in a particular cohort by using the Where() LINQ method
            List <Instructor> cohort34Instructors = allInstructors
                                                    .Where(Instructor => Instructor.Cohort.Name == "Day Cohort 34").ToList();

            // Print out all the instructors in cohort 34
            // Console.WriteLine("===== Cohort 34 Instructors =====");
            foreach (Instructor instructor in cohort34Instructors)
            {
                // Console.WriteLine($"{instructor.FirstName} {instructor.LastName}");
            }

            // Sort the students by their last name
            List <Student> sortedStudents = allStudents
                                            .OrderBy(student => student.LastName).ToList();

            // Print out a list of the sorted students
            // Console.WriteLine("===== Sorted Students =====");
            foreach (Student student in sortedStudents)
            {
                // 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.)

            Student michael  = new Student("Michael", "Stiles", "mstiles", day34);
            Student michelle = new Student("Michelle", "Jimenez", "mjimenez", day34);

            allStudents.Add(michael);
            allStudents.Add(michelle);

            List <Student> slackers = allStudents
                                      .Where(student => student.Exercises.Count() == 0).ToList();

            // Print all the students that aren't working on any exercises
            // Console.WriteLine("=== Students with No Exercises ===");
            foreach (Student student in slackers)
            {
                // 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
            // Sort the students by Exercises.Count()
            List <Student> studentsByExerciseCount = allStudents
                                                     .OrderByDescending(student => student.Exercises.Count()).ToList();

            Student topStudent = studentsByExerciseCount[0];

            // Print studentsByExerciseCount and print the top student
            // Console.WriteLine("===== Top Student =====");
            // Console.WriteLine($"{topStudent.FirstName} {topStudent.LastName}");
            // Console.WriteLine();
            // Console.WriteLine("===== Students By Number of Exercises =====");
            foreach (Student student in studentsByExerciseCount)
            {
                // Console.WriteLine($"{student.FirstName} {student.LastName}: {student.Exercises.Count()} exercises");
            }

            // Display how many students are in each cohort
            var counts = allStudents.GroupBy(student => student.Cohort)
                         .Select(group => new {
                Cohort      = group.Key,
                NumStudents = group.Count()
            });

            // Print number of students in each cohort
            Console.WriteLine("===== Number of Students =====");
            foreach (var cohort in counts)
            {
                Console.WriteLine($"{cohort.Cohort.Name}: {cohort.NumStudents}");
            }
        }
Beispiel #19
0
        static void Main()
        {
            // Creating a few exercises
            Exercise Dictionaries = new Exercise()
            {
                ExerciseName     = "Dictionaries",
                ExerciseLanguage = "C#"
            };
            Exercise EmployeeList = new Exercise()
            {
                ExerciseName     = "Employee List",
                ExerciseLanguage = "JavaScript"
            };
            Exercise EnglishIdioms = new Exercise()
            {
                ExerciseName     = "English Idioms",
                ExerciseLanguage = "C#"
            };
            Exercise RandallsCarLot = new Exercise()
            {
                ExerciseName     = "Randalls Car Lot",
                ExerciseLanguage = "JavaScript"
            };

            // Creating a few cohorts
            Cohort Cohort31 = new Cohort()
            {
                CohortName = "Day Cohort 31"
            };
            Cohort Cohort32 = new Cohort()
            {
                CohortName = "Day Cohort 32"
            };
            Cohort Cohort33 = new Cohort()
            {
                CohortName = "Day Cohort 33"
            };

            // Creating a few students
            Student Billy = new Student()
            {
                FirstName              = "Billy",
                LastName               = "Mitchell",
                SlackHandle            = "William Mitchell",
                ListOfStudentExercises = new List <Exercise>()
            };
            Student Chris = new Student()
            {
                FirstName              = "Chris",
                LastName               = "Morgan",
                SlackHandle            = "Chris Morgan",
                ListOfStudentExercises = new List <Exercise>()
            };
            Student Brian = new Student()
            {
                FirstName   = "Brian",
                LastName    = "Jobe",
                SlackHandle = "Brian Jobe"
            };
            Student Ali = new Student()
            {
                FirstName              = "Ali",
                LastName               = "Abdulle",
                SlackHandle            = "Ali Abdulle",
                ListOfStudentExercises = new List <Exercise>()
            };

            // Creating a few instructors
            Instructor Andy = new Instructor()
            {
                FirstName           = "Andy",
                LastName            = "Collins",
                SlackHandle         = "Andy Collins",
                InstructorSpecialty = "Jokes"
            };
            Instructor Leah = new Instructor()
            {
                FirstName           = "Leah",
                LastName            = "Hoefling",
                SlackHandle         = "Leah Hoefling",
                InstructorSpecialty = "Baking"
            };
            Instructor Jisie = new Instructor()
            {
                FirstName           = "Jisie",
                LastName            = "David",
                SlackHandle         = "Jisie David",
                InstructorSpecialty = "JavaScript"
            };

            //Assigning students to cohorts
            Cohort31.StudentsInCohort.Add(Billy);
            Billy.Cohort = Cohort31;
            Cohort32.StudentsInCohort.Add(Chris);
            Chris.Cohort = Cohort32;
            Cohort33.StudentsInCohort.Add(Brian);
            Brian.Cohort = Cohort33;
            Cohort31.StudentsInCohort.Add(Ali);
            Ali.Cohort = Cohort31;

            //Assigning instructors to cohorts
            Cohort31.InstructorsInCohort.Add(Andy);
            Andy.Cohort = Cohort31;
            Cohort32.InstructorsInCohort.Add(Leah);
            Leah.Cohort = Cohort32;
            Cohort33.InstructorsInCohort.Add(Jisie);
            Jisie.Cohort = Cohort33;

            //Assigning Exercises to Students
            Andy.AssignExercise(Billy, Dictionaries);
            Andy.AssignExercise(Billy, EmployeeList);
            Andy.AssignExercise(Billy, EnglishIdioms);
            Leah.AssignExercise(Chris, Dictionaries);
            Leah.AssignExercise(Chris, EnglishIdioms);
            // Jisie.AssignExercise(Brian, EmployeeList);
            // Jisie.AssignExercise(Brian, RandallsCarLot);
            Leah.AssignExercise(Ali, EnglishIdioms);
            Leah.AssignExercise(Ali, RandallsCarLot);

            List <Student> Students = new List <Student>()
            {
                Billy,
                Chris,
                Brian,
                Ali
            };

            List <Exercise> Exercises = new List <Exercise>()
            {
                Dictionaries,
                EmployeeList,
                EnglishIdioms,
                RandallsCarLot
            };

            List <Instructor> Instructors = new List <Instructor>()
            {
                Andy,
                Leah,
                Jisie
            };

            List <Cohort> Cohorts = new List <Cohort>()
            {
                Cohort31,
                Cohort32,
                Cohort33
            };

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");
            Console.WriteLine("The following students are working these exercises:");
            foreach (Student student in Students)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName} is working on");
                foreach (Exercise exercise in student.ListOfStudentExercises)
                {
                    Console.WriteLine($"{exercise.ExerciseName} using computer language {exercise.ExerciseLanguage}");
                }
            }

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");

            Console.WriteLine("The following list of exercises use JavaScript:");
            foreach (Exercise exercise in Exercises.Where(exercise => exercise.ExerciseLanguage == "JavaScript"))
            {
                Console.WriteLine(exercise.ExerciseName);
            }

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");

            Console.WriteLine("The Day Cohort 31 has the following students:");
            foreach (Student student in Students.Where(student => student.Cohort == Cohort31))
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");

            Console.WriteLine("The Day Cohort 31 has the following instructors:");
            foreach (Instructor instructor in Instructors.Where(instructor => instructor.Cohort == Cohort31))
            {
                Console.WriteLine($"{instructor.FirstName} {instructor.LastName}");
            }

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");

            Console.WriteLine("Here is a list of students at NSS in descending order by last name:");
            foreach (Student student in Students.OrderByDescending(name => name.LastName))
            {
                Console.WriteLine($"{student.FirstName} {student.LastName}");
            }

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");

            foreach (Student student in Students.Where(student => student.ListOfStudentExercises.Count == 0))
            {
                Console.WriteLine($"{student.FirstName} {student.LastName} is currently not working on any exercises");
            }

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");

            // List<Student> studentsNumberOfExercises = new List<Student>();

            // foreach (Student student in Students.OrderByDescending(s => s.ListOfStudentExercises.Count()))
            // {
            //     studentsNumberOfExercises.Add(student);
            // }
            //     var studentWithMostExercises = studentsNumberOfExercises.First();

            // Console.WriteLine("****");
            // Console.WriteLine("The following student is working on the most exercises:");
            // Console.WriteLine(studentWithMostExercises.FirstName);

            Student studentWithMostExercises = Students.OrderByDescending(student =>
                                                                          student.ListOfStudentExercises.Count).ToList()[0];

            Console.WriteLine("The following student is working on the most exercises:");
            Console.WriteLine(studentWithMostExercises.FirstName);

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");

            foreach (Cohort cohort in Cohorts)
            {
                Console.WriteLine($"There are {cohort.StudentsInCohort.Count} students in {cohort.CohortName}");
            }

            Console.WriteLine("");
            Console.WriteLine("********");
            Console.WriteLine("");

            // //Assigning students to cohorts
            // Cohort31.AssignStudentToCohort(Billy);
            // Cohort32.AssignStudentToCohort(Chris);
            // Cohort33.AssignStudentToCohort(Brian);
            // Cohort32.AssignStudentToCohort(Ali);

            // //Assigning instructors to cohorts
            // Cohort31.AssignInstructorToCohort(Andy);
            // Cohort32.AssignInstructorToCohort(Leah);
            // Cohort33.AssignInstructorToCohort(Jisie);

            // //Assigning exercises to students
            // Billy.AssignExerciseToStudent(Dictionaries);
            // Billy.AssignExerciseToStudent(EmployeeList);

            // Chris.AssignExerciseToStudent(Dictionaries);
            // Chris.AssignExerciseToStudent(EnglishIdioms);

            // Brian.AssignExerciseToStudent(EmployeeList);
            // Brian.AssignExerciseToStudent(RandallsCarLot);

            // Ali.AssignExerciseToStudent(EnglishIdioms);
            // Ali.AssignExerciseToStudent(RandallsCarLot);

            // Billy.AddStudent(Billy);
            // Student2.AddStudent(Student2);
            // Brian.AddStudent(Brian);
            // Ali.AddStudent(Ali);

            // Dictionaries.AddExercise(Dictionaries);
            // EmployeeList.AddExercise(EmployeeList);
            // EnglishIdioms.AddExercise(EnglishIdioms);
            // RandallsCarLot.AddExercise(RandallsCarLot);
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            SqliteConnection db = DatabaseInterface.Connection;

            // Create 4, or more, exercises.
            Exercise loops        = new Exercise("loops", "Javascript");
            Exercise objects      = new Exercise("objects", "Javascript");
            Exercise dictionaries = new Exercise("dictionaries", "C#");
            Exercise lists        = new Exercise("lists", "C#");
            // Create 3, or more, cohorts.
            Cohort twentyFive  = new Cohort("Day 25");
            Cohort twentySix   = new Cohort("Day 26");
            Cohort twentySeven = new Cohort("Day 27");
            // Create 4, or more, students and assign them to one of the cohorts.
            Student Sally    = new Student("Sally", "Boucher", "keep it clean", twentyFive);
            Student Bobby    = new Student("Bobby", "Boucher", "Drink some water", twentySix);
            Student Chandler = new Student("Chandler", "Bing", "could I be more ...", twentySix);
            Student Mark     = new Student("Mark", "Hale", "This is hard", twentySeven);
            Student Klaus    = new Student("Klaus", "Hardt", "Hi, guys", twentySeven);
            Student Taylor   = new Student("Taylor", "Gulley", "Mark is a dummy", twentySeven);
            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor Joe   = new Instructor("Joe", "Shepherd", "joes", twentyFive);
            Instructor Jisie = new Instructor("Jisie", "David", "jisie", twentySix);
            Instructor Steve = new Instructor("Steve", "Brownlee", "coach", twentySeven);

            // Have each instructor assign 2 exercises to each of the students.
            Joe.AssignExercise(loops, Sally);
            Joe.AssignExercise(objects, Sally);
            Jisie.AssignExercise(dictionaries, Bobby);
            Jisie.AssignExercise(lists, Bobby);
            Jisie.AssignExercise(lists, Chandler);
            Jisie.AssignExercise(dictionaries, Chandler);
            Steve.AssignExercise(loops, Mark);
            Steve.AssignExercise(objects, Mark);
            Steve.AssignExercise(lists, Mark);
            Steve.AssignExercise(dictionaries, Mark);
            Steve.AssignExercise(lists, Klaus);
            Steve.AssignExercise(dictionaries, Klaus);
            // Steve.AssignExercise (lists, Taylor);
            // Steve.AssignExercise (dictionaries, Taylor);
            // Create a list of students.
            List <Student> students = new List <Student> ()
            {
                Mark,
                Sally,
                Bobby,
                Chandler,
                Klaus,
                Taylor
            };

            // Create a list of exercises.
            List <Exercise> exercises = new List <Exercise> ()
            {
                loops,
                objects,
                dictionaries,
                lists
            };

            //Create a list of Cohorts
            List <Cohort> cohorts = new List <Cohort> ()
            {
                twentyFive,
                twentySix,
                twentySeven
            };

            //Create a list of Instructors
            List <Instructor> instructors = new List <Instructor> ()
            {
                Joe,
                Jisie,
                Steve
            };

            // Generate a report that displays which students are working on which exercises.
            // foreach (Exercise ex in exercises) {
            //     List<string> assignedStudents = new List<string> ();
            //     foreach (Student stu in students) {
            //         if (stu.Exercises.Contains (ex)) {
            //             assignedStudents.Add (stu.FirstName);
            //         }
            //     }
            //     Console.WriteLine ($"{ex.Name} is being worked on by {String.Join(", ", assignedStudents)}");
            // }

            // 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;

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

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

            // foreach (Student student in studentsInCohort25) {
            //     Console.WriteLine ($"Student in Cohort 25: {student.FirstName} {student.LastName}");
            // }

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

            // foreach (Student student in studentsInCohort26) {
            //     Console.WriteLine ($"Student in Cohort 26: {student.FirstName} {student.LastName}");
            // }

            IEnumerable <Student> studentsInCohort27 = from student in students
                                                       where student.Cohort == twentySeven
                                                       select student;

            // foreach (Student student in studentsInCohort27) {
            //     Console.WriteLine ($"Student in Cohort 27: {student.FirstName} {student.LastName}");
            // }

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

            // foreach (Instructor Instructor in instructorsInCohort25) {
            //     Console.WriteLine ($"Instructor for Cohort 25: {Instructor.FirstName} {Instructor.LastName}");
            // }

            IEnumerable <Instructor> instructorsInCohort26 = from instructor in instructors
                                                             where instructor.Cohort == twentySix
                                                             select instructor;

            // foreach (Instructor Instructor in instructorsInCohort26) {
            //     Console.WriteLine ($"Instructor for Cohort 26: {Instructor.FirstName} {Instructor.LastName}");
            // }

            IEnumerable <Instructor> instructorsInCohort27 = from instructor in instructors
                                                             where instructor.Cohort == twentySeven
                                                             select instructor;

            // foreach (Instructor Instructor in instructorsInCohort27) {
            //     Console.WriteLine ($"Instructor for Cohort 27: {Instructor.FirstName} {Instructor.LastName}");
            // }

            //Sort the students by their last name.

            IEnumerable <Student> studentLastNameSort = from student in students
                                                        orderby student.LastName
                                                        select student;

            // foreach (Student student in studentLastNameSort) {
            //     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.)
            IEnumerable <Student> studentsWithNoExercises = from student in students
                                                            where student.Exercises.Count == 0
                                                            select student;

            // foreach(Student student in studentsWithNoExercises){
            //     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.
            var studentWithMostExercises = (from s in students
                                            // select is like .map and generates a new thing and put it into the final collection
                                            select new {
                FirstName = s.FirstName,
                Exercises = s.Exercises.Count()
            })
                                           // put in order of descending number of exercises
                                           .OrderByDescending(s => s.Exercises)
                                           // grab just the first one -> first or default if the list is empty
                                           .Take(1).ToList() [0];
            // Console.WriteLine($"Student working on most exercises: {studentWithMostExercises.FirstName} {studentWithMostExercises.Exercises}");

            // 7. How many students in each cohort?
            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");
            // }

            // Generate a report that displays which students are working on which exercises.
            foreach (Exercise ex in exercises)
            {
                List <string> assignedStudents = new List <string> ();

                foreach (Student stu in students)
                {
                    if (stu.Exercises.Contains(ex))
                    {
                        assignedStudents.Add(stu.FirstName);
                    }
                }
                // Console.WriteLine ($"{ex.Name} is being worked on by {String.Join(", ", assignedStudents)}");
            }

            //Query the database for all the Exercises.
            List <Exercise> AllExercises = db.Query <Exercise> (@"SELECT * FROM EXERCISES").ToList();

            // AllExercises.ForEach(exercise => Console.WriteLine($"{exercise.ExerciseName}"));

            // Fnd all the exercises in the database where the language is JavaScript.
            // List<Exercise> AllJavaScriptExercises = db.Query<Exercise> (@"SELECT * FROM EXERCISES WHERE ExerciseLanguage=='Javascript'").ToList ();
            // AllJavaScriptExercises.ForEach (exercise => Console.WriteLine ($"{exercise.ExerciseName}"));

            //Insert a new exercise into the database.
            // db.Execute (@"INSERT INTO EXERCISES (ExerciseName, ExerciseLanguage) VALUES ('Planets', 'Javascript');");
            // List<Exercise> AllJavaScriptExercises = db.Query<Exercise> (@"SELECT * FROM EXERCISES WHERE ExerciseLanguage=='Javascript'").ToList ();
            // AllJavaScriptExercises.ForEach (exercise => Console.WriteLine ($"{exercise.ExerciseName}"));

            // Find all instructors in the database.Include each instructor's cohort.

            db.Query <Instructor, Cohort, Instructor>(@"
                SELECT  i.FirstName,
                        i.LastName,
                        c.Id,
                        c.CohortName
                FROM Instructor i
                JOIN Cohort c on c.Id = I.Id
            ", (instructor, cohort) =>
            {
                instructor.Cohort = cohort;
                return(instructor);
            }).ToList().ForEach(ins => Console.WriteLine($"{ins.FirstName} {ins.LastName} works in the {ins.Cohort.CohortName}"));


            //Insert a new instructor into the database.Assign the instructor to an existing cohort.

            // Assign an existing exercise to an existing student.

            // Challenge - Find all the students in the database.Include each student's cohort AND each student's list of exercises.
        }
 public Instructor(string fname, string lname, string slack, string specTalent, Cohort cohort)
 {
     FirstName     = fname;
     LastName      = lname;
     SlackHandle   = slack;
     SpecialTalent = specTalent;
     Cohort        = cohort;
 }
Beispiel #22
0
        static void Main(string[] args)
        {
            var FizzBuzz = new Exercise()
            {
                Name     = "FizzBuzz",
                Language = "Javascript"
            };
            var UrbanPlanner = new Exercise()
            {
                Name     = "UrbanPlanner",
                Language = "C#"
            };
            var Kennel = new Exercise()
            {
                Name     = "Kennel",
                Language = "React"
            };
            var DailyJournal = new Exercise()
            {
                Name     = "DailyJournal",
                Language = "Javascript"
            };
            var StudentExercises = new Exercise()
            {
                Name     = "StudentExercises",
                Language = "C#"
            };

            var cohort32 = new Cohort()
            {
                Name = "Cohort 32"
            };

            var cohort33 = new Cohort()
            {
                Name = "Cohort 33"
            };

            var cohort34 = new Cohort()
            {
                Name = "Cohort34"
            };

            var jWebb = new Student()
            {
                FirstName = "Josh",
                LastName  = "Webb",
                Slack     = "Josh-Webb",
                Cohort    = cohort32
            };

            var eClarke = new Student()
            {
                FirstName = "Eliot",
                LastName  = "Clarke",
                Slack     = "Eliot",
                Cohort    = cohort32
            };

            var eAshe = new Student()
            {
                FirstName = "Ellie",
                LastName  = "Ashe",
                Slack     = "Ellie-Ashe",
                Cohort    = cohort34
            };

            var kCard = new Student()
            {
                FirstName = "Keisha",
                LastName  = "Card",
                Slack     = "Keisha C",
                Cohort    = cohort33
            };

            var dSteponawich = new Student()
            {
                FirstName = "Dejan",
                LastName  = "Stepfonavich",
                Slack     = "Dejan S",
                Cohort    = cohort34
            };

            var oPlank = new Student()
            {
                FirstName = "Olivia",
                LastName  = "Plank",
                Slack     = "Soft Boi",
                Cohort    = cohort33
            };

            var bNilsen = new Instructor()
            {
                FirstName  = "Bryan",
                LastName   = "Wilson",
                Slack      = "Bryan Nilsen",
                Cohort     = cohort34,
                Speciality = "High Fives"
            };

            var rHecht = new Instructor()
            {
                FirstName  = "Robbie",
                LastName   = "Hecht",
                Slack      = "Robbiehecht",
                Cohort     = cohort32,
                Speciality = "Singer/Song-writer"
            };

            var aShaefer = new Instructor()
            {
                FirstName  = "Addam",
                LastName   = "Shaefer",
                Slack      = "Addam Shaefer",
                Cohort     = cohort33,
                Speciality = "Hats"
            };

            List <Student> students = new List <Student>()
            {
                eAshe,
                kCard,
                dSteponawich,
                eClarke,
                jWebb,
                oPlank
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                FizzBuzz, UrbanPlanner, Kennel, DailyJournal, StudentExercises
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                bNilsen, aShaefer, rHecht
            };


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

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

            bNilsen.Assign(FizzBuzz, eAshe);
            bNilsen.Assign(DailyJournal, eAshe);
            bNilsen.Assign(Kennel, kCard);
            bNilsen.Assign(UrbanPlanner, kCard);
            bNilsen.Assign(StudentExercises, dSteponawich);
            bNilsen.Assign(Kennel, dSteponawich);
            bNilsen.Assign(DailyJournal, eClarke);
            bNilsen.Assign(Kennel, eClarke);
            bNilsen.Assign(StudentExercises, jWebb);
            bNilsen.Assign(UrbanPlanner, jWebb);
            bNilsen.Assign(DailyJournal, jWebb);

            rHecht.Assign(Kennel, eAshe);
            rHecht.Assign(DailyJournal, eAshe);
            rHecht.Assign(FizzBuzz, kCard);
            rHecht.Assign(DailyJournal, kCard);
            rHecht.Assign(UrbanPlanner, dSteponawich);
            rHecht.Assign(FizzBuzz, dSteponawich);
            rHecht.Assign(StudentExercises, eClarke);
            rHecht.Assign(DailyJournal, eClarke);
            rHecht.Assign(Kennel, jWebb);
            rHecht.Assign(FizzBuzz, jWebb);

            aShaefer.Assign(UrbanPlanner, eAshe);
            aShaefer.Assign(StudentExercises, eAshe);
            aShaefer.Assign(StudentExercises, kCard);
            aShaefer.Assign(UrbanPlanner, kCard);
            aShaefer.Assign(StudentExercises, dSteponawich);
            aShaefer.Assign(Kennel, dSteponawich);
            aShaefer.Assign(DailyJournal, eClarke);
            aShaefer.Assign(Kennel, eClarke);
            aShaefer.Assign(StudentExercises, jWebb);
            aShaefer.Assign(UrbanPlanner, jWebb);

            cohort32.Students.Add(jWebb);
            cohort32.Students.Add(eClarke);
            cohort33.Students.Add(kCard);
            cohort33.Students.Add(oPlank);
            cohort34.Students.Add(dSteponawich);
            cohort34.Students.Add(eAshe);


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


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

            Console.WriteLine($"Exercise 1 is {exercises[0].Name}");

            IEnumerable <Exercise> javascriptExercises = from exercise in exercises
                                                         where exercise.Language == "Javascript"
                                                         select exercise;

            foreach (Exercise e in javascriptExercises)
            {
                Console.WriteLine($"{e.Name} ${e.Language}");
            }

            IEnumerable <Student> cohort32List = from student in students
                                                 where student.Cohort == cohort32
                                                 select student;

            foreach (Student s in cohort32List)
            {
                Console.WriteLine($"{s.FirstName} {s.LastName} is in Cohort 32.");
            }

            IEnumerable <Instructor> cohort32Instructors = from instructor in instructors
                                                           where instructor.Cohort == cohort32
                                                           select instructor;

            foreach (Instructor i in cohort32Instructors)
            {
                Console.WriteLine($"{i.FirstName} {i.LastName} is an instructor for Cohort 32");
            }

            IEnumerable <Student> orderLastName = from student in students
                                                  orderby student.LastName
                                                  select student;

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

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

            foreach (Student s in noExercises)
            {
                Console.WriteLine($"{s.FirstName} {s.LastName} doesn't have any exercises.");
            }

            var mostExercises = students.OrderByDescending(student => student.Exercises.Count()).Take(1);

            foreach (Student s in mostExercises)
            {
                Console.WriteLine($"{s.FirstName} {s.LastName} has the most exercises.");
            }



            foreach (var cohort in cohorts)
            {
                Console.WriteLine($"{cohort.Name} has {cohort.Students.Count()} students.");
            }
        }
        static void Main(string[] args)
        {
            Exercise ChickenMonkey = new Exercise();

            ChickenMonkey.id       = 1;
            ChickenMonkey.Name     = "ChickenMonkey";
            ChickenMonkey.Language = "Javascript";

            Exercise TreeChallenge = new Exercise();

            TreeChallenge.id       = 2;
            TreeChallenge.Name     = "Tree Challenge";
            TreeChallenge.Language = "Javascript";

            Exercise StudentExercises = new Exercise();

            StudentExercises.id       = 3;
            StudentExercises.Name     = "Student Exercises";
            StudentExercises.Language = "C#";

            Exercise EnglishIdioms = new Exercise();

            EnglishIdioms.id       = 4;
            EnglishIdioms.Name     = "English Idioms";
            EnglishIdioms.Language = "C#";

            Exercise HowManySocks = new Exercise();

            HowManySocks.id       = 5;
            HowManySocks.Name     = "How Many Socks?";
            HowManySocks.Language = "Python";

            Exercise KandyKorner = new Exercise();

            KandyKorner.id       = 6;
            KandyKorner.Name     = "Kandy Korner";
            KandyKorner.Language = "React";

            Cohort Cohort32 = new Cohort();

            Cohort32.CohortId   = 32;
            Cohort32.CohortTime = "Day";

            Cohort Cohort34 = new Cohort();

            Cohort34.CohortId   = 34;
            Cohort34.CohortTime = "Day";

            Cohort Cohort10 = new Cohort();

            Cohort10.CohortId   = 10;
            Cohort10.CohortTime = "Night";

            Cohort Cohort35 = new Cohort();

            Cohort35.CohortId   = 35;
            Cohort35.CohortTime = "Day";

            Student Student1 = new Student();

            Student1.id          = 1;
            Student1.FirstName   = "Eliot";
            Student1.LastName    = "Clarke";
            Student1.SlackHandle = "Eliot";
            Student1.Cohort      = 32;

            Student Student2 = new Student();

            Student2.id          = 2;
            Student2.FirstName   = "Jason";
            Student2.LastName    = "Brooks";
            Student2.SlackHandle = "JBrooks";
            Student2.Cohort      = 32;

            Student Student3 = new Student();

            Student3.id          = 3;
            Student3.FirstName   = "Jacob";
            Student3.LastName    = "Best-Wittenberg";
            Student3.SlackHandle = "JacobWittenberg";
            Student3.Cohort      = 35;

            Student Student4 = new Student();

            Student4.id          = 4;
            Student4.FirstName   = "Sean";
            Student4.LastName    = "Glavin";
            Student4.SlackHandle = "S.Glavin";
            Student4.Cohort      = 32;

            Student Student5 = new Student();

            Student5.id          = 5;
            Student5.FirstName   = "Shelley";
            Student5.LastName    = "Arnold";
            Student5.SlackHandle = "ItShelley";
            Student5.Cohort      = 32;

            Instructor Instructor1 = new Instructor();

            Instructor1.id          = 1;
            Instructor1.FirstName   = "Steve";
            Instructor1.LastName    = "Brownlee";
            Instructor1.SlackHandle = "coach";
            Instructor1.Cohort      = 34;
            Instructor1.Specialty   = "Pure Knowledge";

            Instructor Instructor2 = new Instructor();

            Instructor2.id          = 2;
            Instructor2.FirstName   = "Adam";
            Instructor2.LastName    = "Shaeffer";
            Instructor2.SlackHandle = "TheAdam";
            Instructor2.Cohort      = 32;
            Instructor2.Specialty   = "Topical Humor";

            Instructor Instructor3 = new Instructor();

            Instructor3.id          = 3;
            Instructor1.FirstName   = "Jisie";
            Instructor1.LastName    = "David";
            Instructor1.SlackHandle = "j-daaavey";
            Instructor1.Cohort      = 32;
            Instructor1.Specialty   = "Experience";

            Instructor Instructor4 = new Instructor();

            Instructor4.id          = 4;
            Instructor4.FirstName   = "Bryan";
            Instructor4.LastName    = "Nilsen";
            Instructor4.SlackHandle = "BryanF*ckingNilsen";
            Instructor4.Cohort      = 33;
            Instructor4.Specialty   = "High Fives";

            Instructor1.AssignExercise(Student5, ChickenMonkey);
            Instructor1.AssignExercise(Student4, ChickenMonkey);

            Instructor2.AssignExercise(Student1, StudentExercises);
            Instructor2.AssignExercise(Student1, TreeChallenge);

            Instructor3.AssignExercise(Student2, EnglishIdioms);
            Instructor3.AssignExercise(Student4, HowManySocks);

            Instructor4.AssignExercise(Student1, KandyKorner);
            Instructor4.AssignExercise(Student2, TreeChallenge);

            List <Student> students = new List <Student>()
            {
                Student1, Student2, Student3, Student4, Student5
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                ChickenMonkey, TreeChallenge, StudentExercises, EnglishIdioms, HowManySocks, KandyKorner
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                Cohort10, Cohort32, Cohort34, Cohort35
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                Instructor1, Instructor2, Instructor3, Instructor4
            };

            exercises.ForEach(exe =>
            {
                var exerciseId = exe.id;
                Console.WriteLine();
                Console.WriteLine($"Current Students working on {exe.Name} are:");

                students.ForEach(stu =>
                {
                    stu.CurrentExercises.ForEach(currentExe =>
                    {
                        if (exe.id == currentExe.id)
                        {
                            Console.WriteLine($"{stu.FirstName} {stu.LastName}");
                        }
                    });
                });
            });
            Console.WriteLine();

            IEnumerable <Exercise> jsExercises =
                from exercise in exercises
                where exercise.Language == "Javascript"
                select exercise;

            IEnumerable <Student> students32 =
                from student in students
                where student.Cohort == 32
                select student;

            IEnumerable <Instructor> instructors32 =
                from instructor in instructors
                where instructor.Cohort == 32
                select instructor;

            List <Student> orderedStudents = students.OrderBy(n => n.LastName).ToList();

            IEnumerable <Student> newStudents =
                from student in students
                where student.CurrentExercises.Count == 0
                select student;

            Student busyStudent = students.OrderByDescending(n => n.CurrentExercises.Count).ToList()[0];

            var cohortCount =
                from student in students
                join cohort in cohorts on student.Cohort equals cohort.CohortId
                group student by student.Cohort into cohortGroup

                //unecessary list, but still cool that you can just make a list on the fly with LET
                let studentList = cohortGroup
                                  select new
            {
                Cohort      = cohortGroup.Key,
                studentList = studentList
            };



            foreach (var group in cohortCount)
            {
                Console.WriteLine();
                Console.WriteLine($"There are {group.studentList.Count()} in Cohort {group.Cohort}:");
                foreach (var student in group.studentList)
                {
                    Console.WriteLine($"{student.FirstName} {student.LastName}");
                }
            }
        }
Beispiel #24
0
    static void Main(string[] args)
    {
      Exercise ChickenMonkey = new Exercise("ChickenMonkey", "JavaScript");
      Exercise PlanYourHeist = new Exercise("Plan Your Heist", "C#");
      Exercise GlassdalePD = new Exercise("Glassdale PD", "JavaScript");
      Exercise Nutshell = new Exercise("Nutshell", "React");

      Cohort Day36 = new Cohort("Day Cohort 36");
      Cohort Day37 = new Cohort("Day Cohort 36");

      Student GuyC = new Student("Guy", "Cherkesky", "cherkesk", Day36);
      Student DanielF = new Student("Daniel", "Fuqua", "@Daniel Fuqua", Day37);
      Student HoldenP = new Student("Holden", "Parker", "@Holden Parker", Day36);
      Student MattC = new Student("Matt", "Crook", "@Matt Crook", Day36);
      Student DouieN = new Student("Douie", "Notheen", "@DoesNothing", Day36);

      Instructor JoeS = new Instructor("Joe", "Shepherd", "joeshep", "jokes", Day36);
      Instructor SteveB = new Instructor("Steve", "Brownlee", "tech", "@coach", Day37);

      JoeS.AssignExercise(ChickenMonkey, HoldenP);
      JoeS.AssignExercise(GlassdalePD, HoldenP);
      JoeS.AssignExercise(Nutshell, HoldenP);
      JoeS.AssignExercise(ChickenMonkey, GuyC);
      JoeS.AssignExercise(GlassdalePD, GuyC);


    //   List<Student> students = new List<Student>() {
    //     GuyC,
    //     DanielF,
    //     HoldenP,
    //     MattC,
    //     DouieN
    // };
    //   List<Exercise> exercises = new List<Exercise>() {
    //     ChickenMonkey,
    //     PlanYourHeist,
    //     GlassdalePD,
    //     Nutshell
    // };
    //  List<Instructor> instructors = new List<Instructor>(){
    //      JoeS
    //  };

    // List<Cohort> cohorts = new List<Cohort>(){
    //     Day36,
    //     Day37
    // };


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

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

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

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

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

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

      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.First} {student.Last}");
      }

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

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

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

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

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

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

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

      Console.WriteLine($"{studentMostExercises.First} {studentMostExercises.Last} 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}.");
      }
    // // ***************************** Phase 2 *****************************



    }
        static void Main(string[] args)
        {
            // Exercises
            Exercise chickenMonkey = new Exercise()
            {
                ExerciseName = "Chicken Monkey",
                Language     = "JavaScript"
            };

            Exercise battleOfBands = new Exercise();

            battleOfBands.ExerciseName = "Battle of the Bands";
            battleOfBands.Language     = "JavaScript";

            Exercise Library = new Exercise()
            {
                ExerciseName = "Library",
                Language     = "C#"
            };

            Exercise reactNutshell = new Exercise();

            reactNutshell.ExerciseName = "React Nutshell";
            reactNutshell.Language     = "JSX";

            // Cohorts
            Cohort unicorn = new Cohort()
            {
                CohortName = "Unicorn"
            };

            Cohort velociraptor = new Cohort();

            velociraptor.CohortName = "Velociraptor";


            Cohort cyclops = new Cohort()
            {
                CohortName = "Cyclops"
            };

            // Students
            Student alex = new Student()
            {
                FirstName   = "Alex",
                LastName    = "Axel",
                Cohort      = cyclops,
                SlackHandle = "AxelBeast"
            };

            Student madi = new Student();

            madi.FirstName   = "Madi";
            madi.LastName    = "Bobadi";
            madi.Cohort      = unicorn;
            madi.SlackHandle = "BobadiBambi";

            Student jon = new Student()
            {
                FirstName   = "Jon",
                LastName    = "Tron",
                Cohort      = velociraptor,
                SlackHandle = "JonTron",
            };

            Student helen = new Student();

            helen.FirstName   = "Helen";
            helen.LastName    = "Hades";
            helen.Cohort      = velociraptor;
            helen.SlackHandle = "HelenOfHades";

            Student lily = new Student();

            lily.FirstName   = "Lily";
            lily.LastName    = "Paddington";
            lily.Cohort      = unicorn;
            lily.SlackHandle = "Lillypad";

            // Instructors
            Instructor steve = new Instructor()
            {
                FirstName   = "Steve",
                LastName    = "Madden",
                Cohort      = cyclops,
                SlackHandle = "SteveTheMadManMadden"
            };

            Instructor meg = new Instructor();

            meg.FirstName   = "Meg";
            meg.LastName    = "Armstrong";
            meg.Cohort      = unicorn;
            meg.SlackHandle = "ArmyStrong";

            Instructor kimmy = new Instructor()
            {
                FirstName   = "Kimmy",
                LastName    = "Falcon",
                Cohort      = velociraptor,
                SlackHandle = "Falcon4Life"
            };

            // Assign exercise

            steve.AssignExercise(alex, chickenMonkey);
            kimmy.AssignExercise(helen, chickenMonkey);
            kimmy.AssignExercise(jon, chickenMonkey);
            meg.AssignExercise(madi, chickenMonkey);
            steve.AssignExercise(alex, reactNutshell);
            kimmy.AssignExercise(helen, battleOfBands);
            kimmy.AssignExercise(helen, Library);
            kimmy.AssignExercise(jon, battleOfBands);
            kimmy.AssignExercise(helen, reactNutshell);
            meg.AssignExercise(madi, reactNutshell);
            meg.AssignExercise(madi, Library);

            // Create a list of students
            List <Student> students = new List <Student>()
            {
                alex,
                madi,
                jon,
                helen,
                lily
            };

            // Create a list of exercises
            List <Exercise> exercises = new List <Exercise>()
            {
                chickenMonkey,
                battleOfBands,
                reactNutshell,
                Library
            };

            // Create a list of cohorts
            List <Cohort> cohorts = new List <Cohort>()
            {
                unicorn,
                cyclops,
                velociraptor
            };

            // Create a list of instructors
            List <Instructor> instructors = new List <Instructor>()
            {
                steve,
                kimmy,
                meg
            };

            // Loop through exercise list
            // Create a list for assigned students
            // Loop through student list
            // If a students exercise contains the looped exercise list
            // Aadd an assignedStudent to the exercise by their FullName
            // Console log the list exercises with all the students working on each exercise
            foreach (Exercise exercise in exercises)
            {
                List <string> assignedStudents = new List <string>();
                foreach (Student student in students)
                {
                    if (student.Exercises.Contains(exercise))
                    {
                        assignedStudents.Add(student.FullName);
                    }
                }
                // Console.WriteLine($"{exercise.ExerciseName} is being worked on by {string.Join(", ", assignedStudents)}");
            }

            // List exercises for Javascript with where linq method

            IEnumerable <Exercise> JS = from JavaScript in exercises
                                        where JavaScript.Language == "JavaScript"
                                        select JavaScript;

            JS.ToList().ForEach(e => Console.WriteLine(e.ExerciseName));

            // List students in a cohort with linq method
            IEnumerable <Student> stu = from student in students
                                        where student.Cohort == velociraptor
                                        select student;

            stu.ToList().ForEach(s => Console.WriteLine($"{s.FullName} is in Cohort {s.Cohort.CohortName}"));

            // List instructors in a cohort with linq method
            IEnumerable <Instructor> inst = from instructor in instructors
                                            where instructor.Cohort == velociraptor
                                            select instructor;

            inst.ToList().ForEach(i => Console.WriteLine($"{i.FirstName} {i.LastName} teaches {i.Cohort.CohortName}"));

            // List students by their lastname

            var stud = students.Select(s => s.LastName);

            stud.ToList().ForEach(s => Console.WriteLine(s));

            // Display students that aren't working on exercises

            IEnumerable <Student> studies = from student in students
                                            where student.Exercises.Count() == 0
                                            select student;

            studies.ToList().ForEach(study => Console.WriteLine(study.FullName));

            // Which student is working on the most exercises? Make sure one of your students has more exercises than the others.
            var mostStudent = (from student in students
                               orderby student.Exercises.Count() descending
                               select new { FirstName = student.FirstName, Exercises = student.Exercises.Count() }).ToList().FirstOrDefault();

            Console.WriteLine($"The student with the most exercises is {mostStudent.FirstName}");

            // How many students in each cohort?

            var numberStudents = from student in students
                                 group student by student.Cohort into studentNumber
                                 select new {
                Cohort   = studentNumber.Key,
                Students = studentNumber.ToList()
            };

            numberStudents.ToList().ForEach(numbered => Console.WriteLine($"{numbered.Cohort.CohortName} has {numbered.Students.Count()} students"));
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Create 4, or more, exercises.
            Exercise kennel = new Exercise()
            {
                Name     = "Kennel",
                Language = "React"
            };
            Exercise donutShop = new Exercise()
            {
                Name     = "Donut Shop",
                Language = "JS"
            };
            Exercise coinPurse = new Exercise()
            {
                Name     = "Coin Purse",
                Language = "JS"
            };
            Exercise monkeySee = new Exercise()
            {
                Name     = "Monkey See Monkey Do",
                Language = "HTML/CSS"
            };

            // Create 3, or more, cohorts.
            Cohort thirtyfive = new Cohort("35 Day");
            Cohort thirtysix  = new Cohort("36 Day");
            Cohort eleven     = new Cohort("11 Evening");

            // Create 4, or more, students and assign them to one of the cohorts.
            Student one = new Student("Sage", "Klein");

            thirtyfive.AddStudent(one);
            Student two = new Student("John", "Smith");

            thirtyfive.AddStudent(two);
            Student three = new Student("Bryan", "Google");

            eleven.AddStudent(three);
            Student four = new Student("Jessic", "Smot");

            thirtysix.AddStudent(four);

            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor five = new Instructor("Brenda", "L");

            thirtyfive.AddInstructor(five);
            Instructor six = new Instructor("Joe", "S");

            thirtyfive.AddInstructor(six);
            Instructor seven = new Instructor("Adam", "S");

            eleven.AddInstructor(seven);

            // Have each instructor assign 2 exercises to each of the students.
            five.AssignExercise(three, donutShop);
            // five.AssignExercise(four, donutShop);
            six.AssignExercise(two, kennel);
            seven.AssignExercise(one, coinPurse);

            //add students to a list
            List <Student> studentsList = new List <Student>()
            {
                one,
                two,
                three,
                four
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                kennel,
                donutShop,
                coinPurse,
                monkeySee
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                five,
                six,
                seven
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                thirtyfive,
                thirtysix,
                eleven
            };

            var jsExercises = exercises.Where(exercise =>
            {
                return(exercise.Language == "JS");
            });

            // var c35Students = studentsList.Where(student => {
            //   return student.Cohort == ""
            // });

            // var studentsOrderByLastName = studentsList.OrderBy(student >= {
            //   return students.LastName
            // });

            // var studentsWithNoExercises = studentsList.Where(student =>
            // {
            //   int exCount = student.Exercises.Count;
            // });

            foreach (var item in studentsList)
            {
                Console.WriteLine($"name {item.FirstName}");
            }

            var studentWithMostExercises = studentsList.OrderByDescending(student =>
            {
                return(student.Exercises.Count);
            }).FirstOrDefault();

            var orderByLastName = studentsList.OrderBy(student =>
            {
                return(student.LastName);
            });

            // var studentNoExercies = studentsList.Where(student => student.Exercises == 0)
            var studentNoExercies = studentsList.Where(student =>
            {
                int exCount = student.Exercises.Count;
                return(exCount < 1);
            });

            //GroupBy
            //picture a sign above each group

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

            foreach (var group in groups)
            {
                Console.WriteLine($"There are {group.Count()} students in {group.Key}");
            }
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            // Create 4, or more, exercises.
            Exercise Nutshell = new Exercise("Nutshell")
            {
                ExerciseLanguage = "Javascript"
            };
            Exercise WelcomeToNashville = new Exercise("Welcome To Nashville")
            {
                ExerciseLanguage = "HTML/CSS"
            };
            Exercise Capstone = new Exercise("Lawn and Order")
            {
                ExerciseLanguage = "React"
            };
            Exercise ThisProject = new Exercise("Student Exercises")
            {
                ExerciseLanguage = "C Sharp"
            };

            // Create 3, or more, cohorts.
            Cohort C30 = new Cohort("Cohort 30");
            Cohort C29 = new Cohort("Cohort 29");
            Cohort C28 = new Cohort("Cohort 28");

            // Create 4, or more, students and assign them to one of the cohorts.
            Student SamCronin = new Student("Sam", "Cronin", "croninsw")
            {
                cohort = C30
            };

            Student BrianNeal = new Student("Brian", "Neal", "BigDong214")
            {
                cohort = C29
            };

            Student AbbeyBrown = new Student("Abbey", "Brown", "theOleAB")
            {
                cohort = C30
            };

            Student ConnorBailey = new Student("Connor", "Bailey", "goldenRod6969420")
            {
                cohort = C30
            };

            Student DominicKantrude = new Student("Dominic", "Kantrude", "kanDo")
            {
                cohort = C30
            };

            Student KaterinaFreeman = new Student("Katerina", "Freeman", "katWoman")
            {
                cohort = C29
            };

            // Create 3, or more, instructors and assign them to one of the cohorts.
            Instructor SteveBrownlee = new Instructor("Steve", "Brownlee", "coach")
            {
                cohort = C30
            };

            Instructor JoeShepard = new Instructor("Joe", "Shepard", "joes")
            {
                cohort = C29
            };

            Instructor Jissie = new Instructor("Jissie", "LastName", "Jissie")
            {
                cohort = C28
            };

            // Have each instructor assign 2 exercises to each of the students.
            SteveBrownlee.AddExercise(SamCronin, Nutshell);
            SteveBrownlee.AddExercise(SamCronin, Capstone);
            SteveBrownlee.AddExercise(BrianNeal, WelcomeToNashville);
            SteveBrownlee.AddExercise(BrianNeal, Capstone);
            SteveBrownlee.AddExercise(AbbeyBrown, ThisProject);
            SteveBrownlee.AddExercise(AbbeyBrown, WelcomeToNashville);
            SteveBrownlee.AddExercise(ConnorBailey, ThisProject);
            SteveBrownlee.AddExercise(ConnorBailey, Nutshell);

            JoeShepard.AddExercise(SamCronin, WelcomeToNashville);
            JoeShepard.AddExercise(SamCronin, ThisProject);
            JoeShepard.AddExercise(BrianNeal, WelcomeToNashville);
            JoeShepard.AddExercise(BrianNeal, Capstone);
            JoeShepard.AddExercise(AbbeyBrown, ThisProject);
            JoeShepard.AddExercise(AbbeyBrown, WelcomeToNashville);
            JoeShepard.AddExercise(ConnorBailey, ThisProject);
            JoeShepard.AddExercise(ConnorBailey, Nutshell);

            Jissie.AddExercise(SamCronin, Nutshell);
            Jissie.AddExercise(SamCronin, Capstone);
            Jissie.AddExercise(BrianNeal, WelcomeToNashville);
            Jissie.AddExercise(BrianNeal, Capstone);
            Jissie.AddExercise(AbbeyBrown, ThisProject);
            Jissie.AddExercise(AbbeyBrown, WelcomeToNashville);
            Jissie.AddExercise(ConnorBailey, ThisProject);
            Jissie.AddExercise(ConnorBailey, Nutshell);
            Jissie.AddExercise(ConnorBailey, WelcomeToNashville);
            Jissie.AddExercise(ConnorBailey, Capstone);

            List <Student> students = new List <Student>()
            {
                SamCronin,
                BrianNeal,
                AbbeyBrown,
                ConnorBailey,
                DominicKantrude
            };

            List <Exercise> exercises = new List <Exercise>()
            {
                WelcomeToNashville,
                ThisProject,
                Nutshell,
                Capstone
            };

            List <Instructor> instructors = new List <Instructor>()
            {
                SteveBrownlee,
                JoeShepard,
                Jissie
            };

            List <Cohort> cohorts = new List <Cohort>()
            {
                C30,
                C29,
                C28
            };

            IEnumerable <Exercise> jsExercises = from ex in exercises
                                                 where ex.ExerciseLanguage == "Javascript"
                                                 select ex;

            // foreach(Exercise ex in jsExercises)
            // {
            //     Console.WriteLine($"{ex}");
            // }

            IEnumerable <Student> studentsInCohort = from s in students
                                                     where s.cohort == C30
                                                     select s;

            // foreach(Student student in studentsInCohort)
            // {
            //     Console.WriteLine($"{student.FullName}");
            // }

            IEnumerable <Instructor> instructorsInCohort = from i in instructors
                                                           where i.cohort == C30
                                                           select i;

            // foreach(Instructor i in instructorsInCohort)
            // {
            //     Console.WriteLine(i.FullName);
            // }

            IEnumerable <Student> studentsByLastName = from s in students
                                                       orderby s.LastName ascending
                                                       select s;

            // foreach(Student s in studentsByLastName)
            // {
            //     Console.WriteLine(s.FullName);
            // }

            IEnumerable <Student> notWorkingOnExercises = students.Where(student => student.Exercises.Count == 0);

            // foreach(Student s in notWorkingOnExercises)
            // {
            //     Console.WriteLine(s.FullName);
            // }

            Student doingTheMostWork = students.OrderByDescending(student => student.Exercises.Count).First();

            // Console.WriteLine($"Student with most exercises: {doingTheMostWork.FullName}");

            foreach (Cohort cohort in cohorts)
            {
                Console.WriteLine($"{cohort.CohortName} has {cohort.Students.Count} students.");
            }



            // foreach(Student student in students)
            // {
            //     foreach(Exercise exercise in exercises)
            //     {
            //         Console.WriteLine($"{student.FullName} is working on {exercise.ExerciseName}");
            //     }
            // }
        }
Beispiel #28
0
 // public void AddStudents (Student students) {
 //  Students.Add(students);
 //  students.AssignCohort(this);
 // }
 public void AddStudents(Student students, Cohort cohort)
 {
     Students.Add(students);
     students.AssignCohort(cohort);
 }
Beispiel #29
0
        static void Main(string[] args)
        {
            Exercise exercise1 = new Exercise();
            Exercise exercise2 = new Exercise();
            Exercise exercise3 = new Exercise();
            Exercise exercise4 = new Exercise();

            exercise1.Name     = "Chicken Monkey";
            exercise1.Language = "JavaScript";

            exercise2.Name     = "Dollars to Cents";
            exercise2.Language = "JavaScript";

            exercise3.Name     = "Plan Your Heist";
            exercise3.Language = "C Sharp";

            exercise4.Name     = "Calculator";
            exercise4.Language = "C Sharp";

            Cohort cohort1 = new Cohort();
            Cohort cohort2 = new Cohort();
            Cohort cohort3 = new Cohort();

            cohort1.Name = "C34";
            cohort2.Name = "C36";
            cohort3.Name = "E9";

            Student student1 = new Student(cohort1);
            Student student2 = new Student(cohort2);
            Student student3 = new Student(cohort2);
            Student student4 = new Student(cohort3);

            student1.FirstName = "Michael";
            student1.LastName  = "Stiles";

            student2.FirstName = "Bobby";
            student2.LastName  = "Brady";

            student3.FirstName = "Bennett";
            student3.LastName  = "Foster";

            student4.FirstName = "Haroon";
            student4.LastName  = "Iqbal";

            Instructor instructor1 = new Instructor();
            Instructor instructor2 = new Instructor();
            Instructor instructor3 = new Instructor();
            Instructor instructor4 = new Instructor();
            Instructor instructor5 = new Instructor();

            instructor1.Cohort = cohort1;
            instructor2.Cohort = cohort3;
            instructor3.Cohort = cohort2;
            instructor4.Cohort = cohort3;
            instructor5.Cohort = cohort1;

            instructor1.FirstName = "Andy";
            instructor2.FirstName = "Steve";
            instructor3.FirstName = "Jenna";
            instructor4.FirstName = "Bryan";
            instructor5.FirstName = "Adam";

            instructor1.LastName = "Collins";
            instructor2.LastName = "Brownlee";
            instructor3.LastName = "Solis";
            instructor4.LastName = "Nilsen";
            instructor5.LastName = "Sheaffer";


            instructor1.AssignExercise(student1, exercise1);
            instructor1.AssignExercise(student1, exercise2);
            instructor2.AssignExercise(student3, exercise3);
            instructor2.AssignExercise(student4, exercise4);
            instructor3.AssignExercise(student4, exercise2);
            instructor3.AssignExercise(student3, exercise4);
            instructor3.AssignExercise(student3, exercise1);
            instructor3.AssignExercise(student3, exercise2);

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

            students.Add(student1);
            students.Add(student2);
            students.Add(student3);
            students.Add(student4);

            foreach (Student student in students)
            {
                foreach (Exercise studentExercise in student.Exercises)
                {
                    Console.WriteLine($"{student.FirstName} {student.LastName} is working on {studentExercise.Name}");
                }
            }

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



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

            List <Exercise> javascriptExercises = exercises.Where(e => e.Language == "JavaScript").ToList();

            foreach (Exercise exercise in javascriptExercises)
            {
                Console.WriteLine(exercise.Name);
            }

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

            List <Student> cohort36Students = students.Where(s => s.Cohort.Name == "C36").ToList();

            foreach (Student student in cohort36Students)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName} is in Cohort 36");
            }

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

            List <Instructor> instructors = new List <Instructor>()
            {
                instructor1,
                instructor2,
                instructor3,
                instructor4,
                instructor5,
            };

            List <Instructor> cohortE9Instructors = instructors.Where(i => i.Cohort.Name == "E9").ToList();

            foreach (Instructor instructor in cohortE9Instructors)
            {
                Console.WriteLine($"{instructor.FirstName} {instructor.LastName} is an instructor of the E9 cohort");
            }

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

            List <Student> studentsByLastName = students.OrderBy(s => s.LastName).ToList();

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

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

            List <Student> slackerStudents = students.Where(s => s.Exercises.Count == 0).ToList();

            foreach (Student student in slackerStudents)
            {
                Console.WriteLine($"{student.FirstName} {student.LastName} is a slacker");
            }

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

            List <Student> studentsByNumberOfExercises = students.OrderByDescending(s => s.Exercises.Count).ToList();

            Student overachieverStudent = studentsByNumberOfExercises[0];

            Console.WriteLine($"{overachieverStudent.FirstName} {overachieverStudent.LastName} is doing the most exercises");

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

            var groupedByCohort = students
                                  .GroupBy(s => s.Cohort)
                                  .Select(s => new { cohort = s.Key, count = s.Count() });

            foreach (var grouped in groupedByCohort)
            {
                Console.WriteLine($"{grouped.cohort.Name}: {grouped.count}");
            }

            Console.WriteLine("----------------------");
        }
Beispiel #30
0
 public void AddInstructors(Instructor instructors, Cohort cohort)
 {
     Instructors.Add(instructors);
     instructors.AssignCohort(cohort);
 }