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}"); // } // } }
static void Main(string[] args) { // instantiate cohorts Cohort dayCohort40 = new Cohort("Day Cohort 40"); Cohort dayCohort37 = new Cohort("Day Cohort 37"); Cohort dayCohort36 = new Cohort("Day Cohort 36"); // instantiate exercises Exercise nutshell = new Exercise("Nutshell", "React"); Exercise tribute = new Exercise("Celebrity Tribute", "HTML"); Exercise journal = new Exercise("Daily Journal", "JavaScript"); Exercise bangazon = new Exercise("Bangazon", "Python/Django"); // instantiate students Student john = new Student("John", "Long", "JohnALong", "c36"); Student holden = new Student("Holden", "Parker", "HoldenDev", "c37"); Student guy = new Student("Guy", "Cherkesky", "@Guy", "c40"); Student trey = new Student("Trey", "Suitor", "@TreySuitor", "c36"); Student nicole = new Student("Nicole", "Noname", "@nicole", "c40"); Instructor joe = new Instructor("Joe", "Shepherd", "@JoeShep", "c36", "Dad jokes"); Instructor jisie = new Instructor("Jisie", "David", "JisieTheSith", "c40", "Sith Lord"); Instructor brenda = new Instructor("Brenda", "Long", "@BellsMom", "c37", "Front End"); dayCohort36.AddStudent(john); dayCohort36.AddStudent(trey); dayCohort37.AddStudent(holden); dayCohort40.AddStudent(guy); dayCohort40.AddStudent(nicole); dayCohort36.AddInstructor(joe); dayCohort37.AddInstructor(brenda); dayCohort40.AddInstructor(jisie); joe.AddExercise(tribute, john); joe.AddExercise(bangazon, john); joe.AddExercise(nutshell, john); joe.AddExercise(journal, trey); joe.AddExercise(tribute, trey); brenda.AddExercise(journal, holden); brenda.AddExercise(nutshell, holden); jisie.AddExercise(tribute, guy); jisie.AddExercise(bangazon, guy); List <Student> students = new List <Student>() { john, holden, guy, trey, nicole }; List <Exercise> exercises = new List <Exercise>() { bangazon, nutshell, journal, tribute }; List <Cohort> cohorts = new List <Cohort>() { dayCohort36, dayCohort37, dayCohort40 }; List <Instructor> instructors = new List <Instructor>() { joe, brenda, jisie }; // foreach (Exercise exercise in john.Exercises) // { // Console.WriteLine($"{john.FirstName} {john.LastName} has been assigned {exercise.Name}"); // } var jsExercises = exercises.Where(exercise => exercise.Language == "JavaScript"); foreach (var exercise in jsExercises) { Console.WriteLine($"{exercise.Name} is built using {exercise.Language}"); } var c36Students = students.Where(student => student.Cohort == "c36"); foreach (var student in c36Students) { Console.WriteLine($"{student.FirstName} {student.LastName} is in {student.Cohort}"); } var c37Instructors = instructors.Where(instructor => instructor.Cohort == "c37"); foreach (var instructor in c37Instructors) { Console.WriteLine($"{instructor.FirstName} {instructor.LastName} is teaching {instructor.Cohort}"); } var studentsLastName = students.OrderBy(student => student.LastName); Console.WriteLine("Students by last name"); foreach (var student in studentsLastName) { Console.WriteLine($"{student.FirstName} {student.LastName}"); } var studentsNotWorking = students.Where(student => student.Exercises.Count() == 0); foreach (var student in studentsNotWorking) { Console.WriteLine($"{student.FirstName} {student.LastName} has zero exercises assigned."); } var numExercises = 0; foreach (var student in students) { Console.WriteLine($"{student.FirstName} {student.LastName} is working on {student.Exercises.Count()} exercises."); if (student.Exercises.Count() >= numExercises) { numExercises = student.Exercises.Count(); Console.WriteLine($"{student.FirstName} {student.LastName} is working on {numExercises} exercises, and that is the most"); } } foreach (var cohort in cohorts) { Console.WriteLine($"There are {cohort.Students.Count()} students in {cohort.Name}"); } }
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) { // create the exercises Exercise nutshell = new Exercise("nutshell", "React"); Exercise holidayRoad = new Exercise("Holiday Road", "C#"); Exercise fitted = new Exercise("Fitted", "React"); Exercise bangazon = new Exercise("Bangazon", "C#"); //create the cohorts Cohort cohort37 = new Cohort("Cohort 37"); Cohort cohort36 = new Cohort("Cohort 36"); Cohort cohort35 = new Cohort("Cohort 35"); //create the students Student kevin = new Student("Kevin", "Penny", "kpen3", cohort36); Student james = new Student("James", "Nitz", "jitzynitzy", cohort37); Student audrey = new Student("Audrey", "Borgra", "BigBrainBorgra", cohort36); Student namita = new Student("Namita", "Manohar", "namitabannana", cohort37); Student jansen = new Student("Jansen", "Vanderspuy", "simplyJantastic", cohort35); Student garrett = new Student("Garrett", "Freshwater", "gFresh", cohort36); // create the instructors Instructor steve = new Instructor("Steve", "Brownlee", "choortlehort", cohort37, "dad jokes"); Instructor mo = new Instructor("Mo", "Silvera", "MoCodeLessProblems", cohort36, "Cheesecakes"); Instructor leah = new Instructor("Leah", "Hoeffling", "LeahLemurLady", cohort35, "petting lemurs"); // assign the students to cohorts cohort35.AddStudent(jansen); cohort36.AddStudent(kevin); cohort36.AddStudent(audrey); cohort36.AddStudent(garrett); cohort37.AddStudent(james); cohort37.AddStudent(namita); // assign instructors to cohorts cohort35.AddInstructor(leah); cohort36.AddInstructor(mo); cohort37.AddInstructor(steve); // assing exercises to students mo.AddExercise(kevin, fitted); mo.AddExercise(kevin, nutshell); mo.AddExercise(audrey, holidayRoad); mo.AddExercise(audrey, fitted); leah.AddExercise(jansen, nutshell); leah.AddExercise(jansen, bangazon); steve.AddExercise(namita, nutshell); steve.AddExercise(namita, holidayRoad); steve.AddExercise(james, nutshell); steve.AddExercise(james, bangazon); steve.AddExercise(james, fitted); // create list of students var studentsList = new List <Student>(); studentsList.Add(kevin); studentsList.Add(namita); studentsList.Add(audrey); studentsList.Add(james); studentsList.Add(jansen); studentsList.Add(garrett); // create list of exercises var exercisesList = new List <Exercise>(); exercisesList.Add(nutshell); exercisesList.Add(fitted); exercisesList.Add(holidayRoad); exercisesList.Add(bangazon); foreach (Exercise exercise in exercisesList) { Console.WriteLine($"--- {exercise.Name.ToUpper()} ---"); foreach (Student student in studentsList) { foreach (Exercise singleExercise in student.Exercises) { if (singleExercise.Name == exercise.Name) { Console.WriteLine($@"{student.FirstName} {student.LastName}"); Console.WriteLine(" "); } } } } var allReactExercises = exercisesList.Where(langExercise => { return(langExercise.Language == "React"); }); foreach (var langExercise in allReactExercises) { Console.WriteLine(langExercise.Name); } var studentsOrderedByLastName = studentsList.OrderByDescending(student => { return(student.LastName); }); foreach (var student in studentsOrderedByLastName) { Console.WriteLine($"{student.FirstName} {student.LastName}"); } var studentsWithNoExercises = studentsOrderedByLastName.Where(student => { int exercisesCount = student.Exercises.Count; return(exercisesCount == 0); }); Console.WriteLine($"----These students are not working on any exercises----"); foreach (var student in studentsWithNoExercises) { Console.WriteLine($"{student.FirstName} {student.LastName}"); } var studentWithMostExercises = studentsList.OrderByDescending(student => { return(student.Exercises.Count); }).FirstOrDefault(); var groups = studentsList.GroupBy(student => student.Cohort.Name); foreach (var group in groups) { Console.WriteLine($"There are {group.Count()} students in {group.Key}"); } }