static void Main(string[] args) { Exercise dictionaries = new Exercise("Dictionaries", "C#"); Exercise lists = new Exercise("Lists", "C#"); Exercise classes = new Exercise("Classes", "C#"); Exercise urbanPlanner = new Exercise("Urban Planner", "C#"); Exercise conditionals = new Exercise("conditionals", "C#"); Exercise studex = new Exercise("studex", "C#"); Exercise nutshell = new Exercise("nutshell", "JavaScript"); Cohort one = new Cohort("Cohort 1"); Cohort two = new Cohort("Cohort 2"); Cohort three = new Cohort("Cohort 3"); Student Sarah = new Student("Sarah", "Brooks", "@Sarah") { Cohort = three, }; Student Barry = new Student("Barry", "Griffith", "@Barry") { Cohort = three, }; Student Tommy = new Student("Tommy", "Spurlock", "@Tommy Spurlock") { Cohort = one, }; Student Jacob = new Student("Jacob", "Sperry", "@Jacob") { Cohort = two, }; three.listOfStudents.Add(Sarah); three.listOfStudents.Add(Barry); one.listOfStudents.Add(Tommy); two.listOfStudents.Add(Jacob); Instructor Jordan = new Instructor("Jordan", "Castelloe", "@Jordan Castelloe", "Muppets", one); Instructor TommyS = new Instructor("Tommy", "Spurlock", "@Tommy Spurlock", "Mia", two); Instructor Jennifer = new Instructor("Jennifer", "Johnson", "@Jennifer", "Coding", three); three.listOfInstructors.Add(Jordan); two.listOfInstructors.Add(TommyS); one.listOfInstructors.Add(Jennifer); Jordan.Assign(dictionaries, Sarah); Jordan.Assign(lists, Sarah); Jordan.Assign(dictionaries, Barry); Jordan.Assign(lists, Barry); TommyS.Assign(classes, Sarah); TommyS.Assign(urbanPlanner, Sarah); TommyS.Assign(classes, Barry); TommyS.Assign(urbanPlanner, Barry); Jennifer.Assign(conditionals, Sarah); Jennifer.Assign(studex, Sarah); // Jennifer.Assign(conditionals, Barry); // Jennifer.Assign(studex, Barry); dictionaries.assignedStudents.Add(Sarah); dictionaries.assignedStudents.Add(Barry); lists.assignedStudents.Add(Sarah); lists.assignedStudents.Add(Barry); // three.listOfInstructors.ForEach(instructor => Console.WriteLine(instructor.FirstName)); // three.listOfStudents.ForEach(student => Console.WriteLine(student.FirstName)); // Sarah.assignedExercises.ForEach(exercise => Console.WriteLine(exercise.Name)); // Tommy.assignedExercises.ForEach(exercise => Console.WriteLine(exercise.Name)); // Console.WriteLine("\n"); // dictionaries.assignedStudents.ForEach(student => Console.WriteLine(student.FirstName)); // Console.WriteLine("\n"); // studex.assignedStudents.ForEach(student => Console.WriteLine(student.FirstName)); // Student Exercises Pt.2: Using LINQ methods List <Exercise> allExercises = new List <Exercise>() { dictionaries, lists, classes, urbanPlanner, conditionals, studex, nutshell }; List <Exercise> JSexercises = allExercises.Where(exercise => exercise.Language == "JavaScript").ToList(); List <Cohort> cohorts = new List <Cohort>() { one, two, three }; List <Instructor> instructors = new List <Instructor>() { Jordan, TommyS, Jennifer }; List <Instructor> instructorsInCohort3 = instructors.Where(instructor => instructor.Cohort.Name == "Cohort 3").ToList(); List <Student> students = new List <Student>() { Sarah, Barry, Tommy, Jacob }; List <Student> studentsInCohort3 = students.Where(student => student.Cohort.Name == "Cohort 3").ToList(); List <Student> studentsOrderedByLastName = students.OrderBy(student => student.LastName).ToList(); List <Student> studentsNotWorking = students.Where(student => student.assignedExercises.Count() == 0).ToList(); foreach (Student student in studentsNotWorking) { Console.WriteLine($"{student.FirstName} is not working on any exercises."); } Student HardWorkingStudent = students.OrderByDescending(student => student.assignedExercises.Count()).First(); var studentsInCohort = from student in students group student by student.Cohort.Name into cohortGroup select new Dictionary <string, int>() { { cohortGroup.Key, cohortGroup.Count() } }; foreach (Dictionary <string, int> cohortStudents in studentsInCohort) { foreach (KeyValuePair <string, int> student in cohortStudents) { Console.WriteLine($"There are {student.Value} student(s) in {student.Key}"); } } Console.WriteLine(); }
static void Main(string[] args) { // Create 4, or more, exercises. Exercise CelebTribute = new Exercise() { Name = "Celebrity Tribute", Language = "CSS" }; Exercise Itinerary = new Exercise() { Name = "Welcome To Nashville", Language = "Javascript" }; Exercise Nutshell = new Exercise() { Name = "Nutshell", Language = "ReactJs" }; Exercise Csharp = new Exercise() { Name = "practice exercise", Language = "C#" }; // // Create 3, or more, cohorts. Cohort Cohort34 = new Cohort() { Name = "Day Cohort 34", Number = 34 }; Cohort Cohort35 = new Cohort() { Name = "Day Cohort 35", Number = 35 }; Cohort Cohort1 = new Cohort() { Name = "Day Cohort 1", Number = 1 }; // // Create 4, or more, students and assign them to one of the cohorts. Student Michelle = new Student() { FirstName = "Michelle", LastName = "Jimenez", SlackHandle = "mjimeneztn", Cohort = 34 }; Student Billy = new Student() { FirstName = "Billy", LastName = "Bob", SlackHandle = "billybob", Cohort = 34 }; Student Joe = new Student() { FirstName = "Joe", LastName = "Shmo", SlackHandle = "joeshmo", Cohort = 1 }; Student Student4 = new Student() { FirstName = "PersonNme", LastName = "PersonLASTname", SlackHandle = "person1", Cohort = 35 }; // // Create 3, or more, instructors and assign them to one of the cohorts. Instructor Andy = new Instructor() { FirstName = "Andy", LastName = "C", SlackHandle = "AndyCollins", Cohort = 34, Speciality = "Creator of c#" }; Instructor Bryan = new Instructor() { FirstName = "Bryan", LastName = "Nilsen", SlackHandle = "bryannilsen", Cohort = 34, Speciality = "artist" }; Instructor Steve = new Instructor() { FirstName = "Steve", LastName = "Brownlee", SlackHandle = "stevenbrownlee", Cohort = 35, Speciality = "Being awesome" }; // // Have each instructor assign 2 exercises to each of the students. Steve.AssignEx(CelebTribute, Michelle); Steve.AssignEx(Itinerary, Billy); Andy.AssignEx(Nutshell, Michelle); Andy.AssignEx(Csharp, Joe); Bryan.AssignEx(CelebTribute, Billy); Bryan.AssignEx(Itinerary, Joe); Andy.AssignEx(Nutshell, Student4); // Create a list of students and exercises List <Student> students = new List <Student>(); students.AddRange(new[] { Michelle, Billy, Joe }); List <Exercise> exercises = new List <Exercise>(); exercises.AddRange(new[] { CelebTribute, Nutshell, Csharp, Itinerary }); // Generate a report that displays which students are working on which exercises. foreach (Student student in students) { Console.WriteLine($"{student.FirstName} is working on {student.Exercises[1].Name} and {student.Exercises[0].Name}"); } }
static void Main(string[] args) { // Create 4, or more, exercises. var CelebrityTribute = new Exercise() { Name = "Celebrity Tribute", Language = "CSS" }; var Nutshell = new Exercise() { Name = "Nutshell", Language = "JavaScript" }; var Databases = new Exercise() { Name = "Database Basics", Language = "C#" }; var AspSprint = new Exercise() { Name = "ASP .NET Sprint", Language = "C#" }; // // Create 3, or more, cohorts. var Cohort32 = new Cohort() { Name = "Day Cohort 32", Number = 32 }; var Cohort33 = new Cohort() { Name = "Day Cohort 33", Number = 33 }; var Cohort34 = new Cohort() { Name = "Day Cohort 34", Number = 34 }; // // Create 4, or more, students and assign them to one of the cohorts. var Carly = new Student() { FirstName = "Carly", LastName = "Bergthold", SlackHandle = "carlybergthold", Cohort = 32 }; var Jake = new Student() { FirstName = "Jake", LastName = "Preston", SlackHandle = "jakepreston", Cohort = 32 }; var Sydney = new Student() { FirstName = "Sydney", LastName = "Noh", SlackHandle = "sydneynoh", Cohort = 33 }; var Jacquelyn = new Student() { FirstName = "Jacquelyn", LastName = "McCray", SlackHandle = "jacquelynmccray", Cohort = 34 }; var Dummy = new Student() { FirstName = "Dummy", LastName = "Yummy", SlackHandle = "Dummerthendirt", Cohort = 33 }; // // Create 3, or more, instructors and assign them to one of the cohorts. var Adam = new Instructor() { FirstName = "Adam", LastName = "Sheaffer", SlackHandle = "adamsheaffer", Cohort = 32, Speciality = "Dumping on Joel" }; var Bryan = new Instructor() { FirstName = "Bryan", LastName = "Nilsen", SlackHandle = "bryannilsen", Cohort = 34, Speciality = "High fiving" }; var Jisie = new Instructor() { FirstName = "Jisie", LastName = "David", SlackHandle = "jisiedavid", Cohort = 32, Speciality = "Explaining complicated things simply" }; var Steve = new Instructor() { FirstName = "Steve", LastName = "Brownlee", SlackHandle = "stevenbrownlee", Cohort = 33, Speciality = "Complaining about people being quiet on presentation day" }; // // Have each instructor assign 2 exercises to each of the students. Adam.AssignEx(Databases, Carly); Adam.AssignEx(AspSprint, Carly); Adam.AssignNewEx("C#", "C#", Carly); Jisie.AssignEx(AspSprint, Jake); Jisie.AssignNewEx("C#", "C#", Jake); Steve.AssignEx(Nutshell, Sydney); Steve.AssignNewEx("Grunt", "HTML", Sydney); Bryan.AssignEx(CelebrityTribute, Jacquelyn); Bryan.AssignNewEx("Flexbox", "CSS", Jacquelyn); // Create a list of students, intructors, cohorts, and exercises List <Student> students = new List <Student>(); students.AddRange(new[] { Carly, Jake, Sydney, Jacquelyn, Dummy }); List <Instructor> instructors = new List <Instructor>(); instructors.AddRange(new[] { Adam, Bryan, Jisie, Steve }); List <Cohort> cohorts = new List <Cohort>(); cohorts.AddRange(new[] { Cohort32, Cohort33, Cohort34 }); List <Exercise> exercises = new List <Exercise>(); exercises.AddRange(new[] { CelebrityTribute, Nutshell, AspSprint, Databases }); // Generate a report that displays which students are working on which exercises. foreach (var student in students) { var stuExercises = new List <string>(); foreach (var ex in student.Exercises) { stuExercises.Add(ex.Name); } string[] exArray = stuExercises.ToArray(); var exs = string.Join(" and ", exArray); Console.WriteLine($"{student.FirstName} is working on {exs}"); } // List exercises for the JavaScript language by using the Where() LINQ method. IEnumerable <Exercise> JSExercises = from exs in exercises where exs.Language == "JavaScript" select exs; // List students in a particular cohort by using the Where() LINQ method. IEnumerable <Student> Cohort32Students = from stu in students where stu.Cohort == 32 select stu; // List instructors in a particular cohort by using the Where() LINQ method. IEnumerable <Instructor> Cohort32Instructors = instructors.Where(inst => inst.Cohort == 32); // Sort the students by their last name. IEnumerable <Student> stusByName = students.OrderBy(stu => stu.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> noExs = students.Where(stu => stu.Exercises.Count == 0); // // How many students in each cohort? var group = cohorts.GroupJoin(students, m => m.Number, s => s.Cohort, (m, s) => new Result(m.Number, s)); foreach (var result in group) { var stusInCohort = new List <string>(); foreach (var p in result.s) { stusInCohort.Add(p.FirstName); } Console.WriteLine($"Cohort {result.Cohort} has {stusInCohort.Count} students."); } }