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}"); } }
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) { Exercise Exercise1 = new Exercise() { Name = "Function practice", Language = "JavaScript" }; Exercise Exercise2 = new Exercise() { Name = "Array Methods", Language = "JavaScript" }; Exercise Exercise3 = new Exercise() { Name = "Classes", Language = "C#" }; Exercise Exercise4 = new Exercise() { Name = "Basic Queries", Language = "SQL" }; Cohort Day32 = new Cohort() { CohortName = "Cohort 32" }; Cohort Day33 = new Cohort() { CohortName = "Cohort 33" }; Cohort Day34 = new Cohort() { CohortName = "Cohort 34" }; Student Randy = new Student() { FirstName = "Randy", LastName = "BoBandy", SlackHandle = "@TheRealRandy", Cohort = 32 }; Student Lahey = new Student() { FirstName = "Jim", LastName = "Lahey", SlackHandle = "@DrunkLahey", Cohort = 33 }; Student Barb = new Student() { FirstName = "Barb", LastName = "Lahey", SlackHandle = "@BarbsPark", Cohort = 34 }; Student Corey = new Student() { FirstName = "Corey", LastName = "Lahey", SlackHandle = "@SupDude", Cohort = 34 }; Student Phil = new Student() { FirstName = "Philedelpiha", LastName = "Collins", SlackHandle = "@TheDirtyBurger", Cohort = 33 }; Day32.AddStudent(Randy); Day33.AddStudent(Lahey); Day34.AddStudent(Barb); Day34.AddStudent(Corey); Day33.AddStudent(Phil); Instructor Trevor = new Instructor() { FirstName = "Trevor", LastName = "Dennision", SlackHandle = "@TBag", Cohort = 33, Specialty = "JavaScript" }; Instructor Ricky = new Instructor { FirstName = "Ricky", LastName = "Sunnyvale", SlackHandle = "@RickySan", Cohort = 31, Specialty = "C#/.NET" }; Instructor Julian = new Instructor() { FirstName = "Julian", LastName = "Sunnyvale", SlackHandle = "@JulianRules", Cohort = 32, Specialty = "SQL" }; Day32.AddInstructor(Trevor); Day32.AddInstructor(Ricky); Day32.AddInstructor(Julian); Trevor.AssignStudents(Randy, Exercise1); Trevor.AssignStudents(Randy, Exercise2); Ricky.AssignStudents(Lahey, Exercise3); Ricky.AssignStudents(Lahey, Exercise4); Julian.AssignStudents(Barb, Exercise2); Julian.AssignStudents(Barb, Exercise4); Trevor.AssignStudents(Corey, Exercise1); Trevor.AssignStudents(Barb, Exercise3); List <Cohort> cohorts = new List <Cohort>(); cohorts.Add(Day32); cohorts.Add(Day33); cohorts.Add(Day34); List <Instructor> instructors = new List <Instructor>(); instructors.Add(Trevor); instructors.Add(Ricky); instructors.Add(Julian); List <Student> students = new List <Student>(); students.Add(Randy); students.Add(Lahey); students.Add(Barb); students.Add(Corey); students.Add(Phil); List <Exercise> exercises = new List <Exercise>(); exercises.Add(Exercise1); exercises.Add(Exercise2); exercises.Add(Exercise3); exercises.Add(Exercise4); foreach (Student student in students) { Console.WriteLine($"Student: {student.FirstName}"); foreach (Exercise exercise in student.Exercises) { Console.WriteLine($"Exercise: {exercise.Name}"); } } var jsExercises = (from exercise in exercises where exercise.Language == "JavaScript" select exercise); jsExercises.ToList().ForEach(ex => Console.WriteLine($"list of JS exercises: {ex.Name}")); var studentsInCohort = (from student in students where student.Cohort == 34 select student); studentsInCohort.ToList().ForEach(student => Console.WriteLine($"Cohort 34 members: {student.FirstName}{student.LastName}")); var instructorsInCohort = (from instructor in instructors where instructor.Cohort == 33 select instructor); instructorsInCohort.ToList().ForEach(instructor => Console.WriteLine($"Cohort 33 Instructor: {instructor.FirstName} {instructor.LastName}")); var studentsByLast = students.OrderBy(student => student.LastName).ToList(); Console.WriteLine("Students by last name:"); foreach (Student student in students) { Console.WriteLine($"{student.LastName} {student.FirstName}"); } var notWorkingOnShit = (from student in students where student.Exercises.Count == 0 select student); notWorkingOnShit.ToList().ForEach(student => Console.WriteLine($"Students not working on any exercises: {student.FirstName} {student.LastName}")); var mostExercises = students.OrderByDescending(student => student.Exercises.Count()).Take(1); Console.WriteLine("Student with the most exercises assigned: "); foreach (Student student in mostExercises) { Console.WriteLine(student.FirstName); } foreach (var cohort in cohorts) { Console.WriteLine($"{cohort.CohortName} has {cohort.Students.Count()} students"); } }
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) { //exercises var classes = new Exercise("Intro to Classes", "C#"); var dictionaries = new Exercise("Intro to Dictionaries", "C#"); var arrays = new Exercise("Intro to Array Methods", "Javascript"); var objects = new Exercise("Intro to Objects", "Javascript"); //cohorts var d32 = new Cohort("Day Cohort 32"); var n08 = new Cohort("Night Cohort 08"); var d33 = new Cohort("Day Cohort 33"); //students var joeyD = new Student("Joey", "Driscol", "bigJD"); var danS = new Student("Dan", "Storm", "dansDansRevolution"); var deepP = new Student("Deep", "Patel", "DeepThoughts"); var seanG = new Student("Sean", "Glavin", "SGlav"); var joelV = new Student("Joel", "Venable", "JVrook"); var nateF = new Student("Nathan", "Flemming", "NateF"); //instructors var brenda = new Instructor("Brenda", "Long", "Blong", "Making Tacos"); var bryan = new Instructor("Bryan", "Nilsen", "BigBriFive", "High Fives"); var adam = new Instructor("Adam", "Shaeffer", "AShaeffer", "Hats"); d32.AddStudent(joeyD); d33.AddStudent(danS); n08.AddStudent(deepP); d32.AddStudent(seanG); d33.AddStudent(joelV); n08.AddStudent(nateF); d32.AddInstructor(brenda); n08.AddInstructor(bryan); d33.AddInstructor(adam); brenda.AssignExercise(classes, joeyD); brenda.AssignExercise(arrays, seanG); brenda.AssignExercise(objects, joeyD); brenda.AssignExercise(dictionaries, seanG); brenda.AssignExercise(classes, seanG); bryan.AssignExercise(objects, deepP); bryan.AssignExercise(arrays, deepP); adam.AssignExercise(dictionaries, joelV); adam.AssignExercise(arrays, joelV); adam.AssignExercise(arrays, danS); adam.AssignExercise(classes, danS); var allStudents = new List <Student>() { joeyD, joelV, deepP, seanG, danS, nateF }; var allExercises = new List <Exercise>() { classes, dictionaries, arrays, objects }; var allInstructors = new List <Instructor>() { brenda, bryan, adam }; var allCohorts = new List <Cohort>() { d32, d33, n08 }; //List all JS exercises var JavascriptExercises = allExercises.Where(exercise => exercise.language == "Javascript"); System.Console.WriteLine("Javascript Exercises:"); foreach (var ex in JavascriptExercises) { System.Console.WriteLine(ex.name); } // List all students in Cohort 32 var Cohort32Students = allCohorts.Where(cohort => cohort.name == "Day Cohort 32") .SelectMany(cohort => cohort.students); System.Console.WriteLine(""); System.Console.WriteLine("Cohort 32 Students:"); foreach (var student in Cohort32Students) { System.Console.WriteLine(student.firstName + " " + student.lastName); } //List all instructors in Cohort 33 var Cohort33Instructors = allCohorts.Where(cohort => cohort.name == "Day Cohort 33") .SelectMany(cohort => cohort.instructors); System.Console.WriteLine(""); System.Console.WriteLine("Cohort 32 Students:"); foreach (var instructor in Cohort33Instructors) { System.Console.WriteLine(instructor.firstName + " " + instructor.lastName); } //Sort students by last name var studentsByLastName = allStudents.OrderBy(student => student.lastName); System.Console.WriteLine(""); System.Console.WriteLine("Students by last name:"); foreach (var student in studentsByLastName) { System.Console.WriteLine(student.lastName + ", " + student.firstName); } //Find Students with no assigned Exercises var studentsWithNoExercises = allStudents.Where(student => student.exercises.Count() == 0); System.Console.WriteLine(""); System.Console.WriteLine("Students with no assigned Exercises:"); foreach (var student in studentsWithNoExercises) { System.Console.WriteLine(student.firstName + " " + student.lastName); } //List the student with the most exercises assigned var studentWithMostAssignedExercises = allStudents.OrderBy(student => student.exercises.Count()).Take(1); System.Console.WriteLine(""); System.Console.WriteLine("Student with the most exercises assigned"); foreach (Student student in studentWithMostAssignedExercises) { System.Console.WriteLine(student.firstName + " " + student.lastName); } //Number of students in each cohort System.Console.WriteLine(""); System.Console.WriteLine("Number of students in each cohort"); foreach (var cohort in allCohorts) { System.Console.WriteLine(cohort.name + ": " + cohort.students.Count()); } //List what exercises students are working on System.Console.WriteLine(""); foreach (Student student in allStudents) { System.Console.WriteLine($"{student.firstName} {student.lastName} is working on the following exercises"); System.Console.WriteLine("------------------------------------------------"); foreach (Exercise exercise in student.exercises) { System.Console.WriteLine($"{exercise.name} in {exercise.language} language"); } System.Console.WriteLine(""); System.Console.WriteLine(""); } }
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) { Exercise MartinsAquarium = new Exercise() { name = "MartinsAquarium", language = "JavaScript" }; Exercise CongressionalRep = new Exercise() { name = "Congressional Representative", language = "HTML" }; Exercise Nutshell = new Exercise() { name = "Nutshell", language = "React" }; Exercise Buildings = new Exercise() { name = "Buildings", language = "C#" }; Cohort C35 = new Cohort() { name = "Cohort 35" }; Cohort C36 = new Cohort() { name = "Cohort 36" }; Cohort C37 = new Cohort() { name = "Cohort 37" }; Student Sage = new Student() { FirstName = "Sage", LastName = "Foo", SlackHandle = "SageFoo", Cohort = "Cohort 35" }; Student RyanB = new Student() { FirstName = "Ryan", LastName = "Bishop", SlackHandle = "RyanB", Cohort = "Cohort 36" }; Student JohnG = new Student() { FirstName = "John", LastName = "Gilliam", SlackHandle = "JG", Cohort = "Cohort 37" }; Student SpencerT = new Student() { FirstName = "Spencer", LastName = "Truett", SlackHandle = "ST", Cohort = "Cohort 37" }; Student SlackerStudent = new Student() { FirstName = "Slacker", LastName = "McGee", SlackHandle = "SM", Cohort = "Cohort 37" }; C35.AddStudent(Sage); C36.AddStudent(RyanB); C37.AddStudent(JohnG); C37.AddStudent(SpencerT); Instructor SteveB = new Instructor() { FirstName = "Steve", LastName = "Brownlee", SlackHandle = "choortlehort", Specialty = "Dad Jokes", Cohort = "Cohort 35" }; Instructor AdamS = new Instructor() { FirstName = "Adam", LastName = "Sheaffer", SlackHandle = "AdamS", Specialty = "var", Cohort = "Cohort 36" }; Instructor Leah = new Instructor() { FirstName = "Leah", LastName = "Hoefling", SlackHandle = "LemurLeah", Specialty = "Traveling", Cohort = "Cohort 37" }; C35.AddInstructor(SteveB); C36.AddInstructor(AdamS); C37.AddInstructor(Leah); SteveB.assignExercise(Sage, MartinsAquarium); SteveB.assignExercise(Sage, CongressionalRep); SteveB.assignExercise(RyanB, Nutshell); SteveB.assignExercise(RyanB, Buildings); SteveB.assignExercise(JohnG, MartinsAquarium); SteveB.assignExercise(JohnG, Nutshell); SteveB.assignExercise(SpencerT, CongressionalRep); SteveB.assignExercise(SpencerT, Nutshell); SteveB.assignExercise(SpencerT, MartinsAquarium); AdamS.assignExercise(Sage, Nutshell); AdamS.assignExercise(Sage, Buildings); AdamS.assignExercise(RyanB, MartinsAquarium); AdamS.assignExercise(RyanB, CongressionalRep); AdamS.assignExercise(JohnG, Buildings); AdamS.assignExercise(JohnG, CongressionalRep); AdamS.assignExercise(SpencerT, Buildings); AdamS.assignExercise(SpencerT, MartinsAquarium); Leah.assignExercise(Sage, Nutshell); Leah.assignExercise(Sage, MartinsAquarium); Leah.assignExercise(RyanB, MartinsAquarium); Leah.assignExercise(RyanB, Buildings); Leah.assignExercise(JohnG, Nutshell); Leah.assignExercise(JohnG, Buildings); Leah.assignExercise(SpencerT, CongressionalRep); Leah.assignExercise(SpencerT, MartinsAquarium); List<Student> students = new List<Student>(); students.Add(Sage); students.Add(RyanB); students.Add(JohnG); students.Add(SpencerT); students.Add(SlackerStudent); List<Exercise> exercises = new List<Exercise>(); exercises.Add(MartinsAquarium); exercises.Add(CongressionalRep); exercises.Add(Buildings); exercises.Add(Nutshell); List<Instructor> instructors = new List<Instructor>(); instructors.Add(SteveB); instructors.Add(AdamS); instructors.Add(Leah); List<Cohort> cohorts = new List<Cohort>(); cohorts.Add(C35); cohorts.Add(C36); cohorts.Add(C37); // foreach (Exercise exercise in exercises) // { // Console.WriteLine($"{exercise.name}:"); // foreach (Student student in students) // { // foreach (Exercise studentExercise in student.Exercises) // { // if (exercise.name == studentExercise.name) // { // Console.WriteLine($"{student.FirstName} {student.LastName}"); // } // } // } // Console.WriteLine($"--------------------"); // } // List exercises for the JavaScript language by using the Where() LINQ method. // IEnumerable<Exercise> JavaScriptExercises = // from exercise in exercises // where exercise.language == "JavaScript" // select exercise; // foreach (Exercise exercise in JavaScriptExercises) // { // Console.WriteLine(exercise.name); // } // IEnumerable<Student> StudentsInCohort37 = // from student in students // where student.Cohort == "Cohort 37" // select student; // foreach (Student student in StudentsInCohort37) // { // Console.WriteLine(student.FirstName); // } // IEnumerable<Instructor> InstructorsInCohort37 = // from instructor in instructors // where instructor.Cohort == "Cohort 37" // select instructor; // foreach (Instructor instructor in InstructorsInCohort37) // { // Console.WriteLine(instructor.FirstName); // }; // IEnumerable<Student> StudentsByLastName = // from student in students // orderby student.LastName descending // select student; // foreach (Student student in StudentsByLastName) // { // Console.WriteLine(student.LastName); // } // IEnumerable<Student> StudentsWithoutExercises = // from student in students // where student.Exercises.Count == 0 // select student; // foreach (Student student in StudentsWithoutExercises) // { // Console.WriteLine(student.FirstName); // } IEnumerable<Student> StudentWithMostExercises = from student in students orderby student.Exercises.Count() descending select.FirstOrDefault() student; var overachiever = StudentWithMostExercises.FirstOrDefault(); Console.WriteLine(overachiever.FirstName); // IEnumerable<CohortReport> studentsPerCohort = students // .GroupBy(student => student.Cohort) // .Select(Group => // { // return new CohortReport // { // StudentCount = Group.Count(), // CohortName = Group.Key // }; // }); // foreach (CohortReport cohort in studentsPerCohort) // { // Console.WriteLine($"{cohort.CohortName} has {cohort.StudentCount}"); // } }
static void Main(string[] args) { Exercise Exercise1 = new Exercise() { Name = "Object practice", Language = "JavaScript" }; Exercise Exercise2 = new Exercise() { Name = "Array Methods", Language = "JavaScript" }; Exercise Exercise3 = new Exercise() { Name = "LINQ", Language = "C#" }; Exercise Exercise4 = new Exercise() { Name = "Types", Language = "C#" }; Cohort Day32 = new Cohort() { CohortName = "Cohort 32" }; Cohort Day33 = new Cohort() { CohortName = "Cohort 33" }; Cohort Day34 = new Cohort() { CohortName = "Cohort 34" }; Student Deep = new Student() { FirstName = "Deep", LastName = "Patel", SlackHandle = "@ThePatel", Cohort = 32 }; Student Ellie = new Student() { FirstName = "Ellie", LastName = "Ash", SlackHandle = "@TheAsh", Cohort = 33 }; Student Janki = new Student() { FirstName = "Janki", LastName = "Patel", SlackHandle = "@TheJanki", Cohort = 34 }; Student Kishan = new Student() { FirstName = "Kishan", LastName = "Bant", SlackHandle = "@TheBant", Cohort = 34 }; Student Dan = new Student() { FirstName = "Dan", LastName = "Storm", SlackHandle = "@TheStorm", Cohort = 34 }; Day32.AddStudent(Deep); Day32.AddStudent(Ellie); Day32.AddStudent(Janki); Day32.AddStudent(Kishan); Instructor Adam = new Instructor() { FirstName = "Adam", LastName = "Sheaffer", SlackHandle = "@TheSheaffer", Cohort = 33 }; Instructor Kristen = new Instructor { FirstName = "Kristen", LastName = "Norris", SlackHandle = "@TheNorris", Cohort = 31 }; Instructor Jisie = new Instructor() { FirstName = "Jisie", LastName = "David", SlackHandle = "@TheDavid", Cohort = 32 }; Day32.AddInstructor(Adam); Day32.AddInstructor(Kristen); Day32.AddInstructor(Jisie); Adam.AssignStudents(Deep, Exercise1); Adam.AssignStudents(Deep, Exercise2); Kristen.AssignStudents(Ellie, Exercise3); Kristen.AssignStudents(Ellie, Exercise4); Jisie.AssignStudents(Janki, Exercise2); Jisie.AssignStudents(Janki, Exercise4); Adam.AssignStudents(Kishan, Exercise1); Adam.AssignStudents(Janki, Exercise3); List <Cohort> cohorts = new List <Cohort>(); cohorts.Add(Day32); cohorts.Add(Day33); cohorts.Add(Day34); List <Instructor> instructors = new List <Instructor>(); instructors.Add(Adam); instructors.Add(Kristen); instructors.Add(Jisie); List <Student> students = new List <Student>(); students.Add(Deep); students.Add(Ellie); students.Add(Janki); students.Add(Kishan); students.Add(Dan); List <Exercise> exercises = new List <Exercise>(); exercises.Add(Exercise1); exercises.Add(Exercise2); exercises.Add(Exercise3); exercises.Add(Exercise4); foreach (Student student in students) { Console.WriteLine($"Student: {student.FirstName}"); foreach (Exercise exercise in student.Exercises) { Console.WriteLine($"Exercise: {exercise.Name}"); } } Console.WriteLine("------------------------------"); var jsExercises = (from exercise in exercises where exercise.Language == "JavaScript" select exercise); jsExercises.ToList().ForEach(ex => Console.WriteLine($"list of JS exercises: {ex.Name}")); Console.WriteLine("------------------------------"); var studentsInCohort = (from student in students where student.Cohort == 34 select student); studentsInCohort.ToList().ForEach(student => Console.WriteLine($"Cohort 34 members: {student.FirstName}{student.LastName}")); Console.WriteLine("------------------------------"); var instructorsInCohort = (from instructor in instructors where instructor.Cohort == 33 select instructor); instructorsInCohort.ToList().ForEach(instructor => Console.WriteLine($"Cohort 33 Instructor: {instructor.FirstName} {instructor.LastName}")); Console.WriteLine("------------------------------"); var studentsByLast = students.OrderBy(student => student.LastName).ToList(); Console.WriteLine("Students by last name:"); foreach (Student student in students) { Console.WriteLine($"{student.LastName} {student.FirstName}"); } Console.WriteLine("------------------------------"); var notWorkingStudent = (from student in students where student.Exercises.Count == 0 select student); notWorkingStudent.ToList().ForEach(student => Console.WriteLine($"Students not working on any exercises: {student.FirstName} {student.LastName}")); Console.WriteLine("------------------------------"); var mostExercises = students.OrderByDescending(student => student.Exercises.Count()).Take(1); Console.WriteLine("Student with the most exercises assigned: "); foreach (Student student in mostExercises) { Console.WriteLine($"{student.FirstName} {student.LastName}"); } Console.WriteLine("------------------------------"); foreach (var cohort in cohorts) { Console.WriteLine($"{cohort.CohortName} has {cohort.Students.Count()} students"); } 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}"); } }