static void Main(string[] args) { Console.WriteLine("STIZZUDENTS!"); List <Student> studentsList = new List <Student>(); List <Exercise> exercisesList = new List <Exercise>(); Exercise nutshell = new Exercise("nutshell", "react"); Exercise holidayroad = new Exercise("holiday road", "javascript"); Exercise planner = new Exercise("urban planner", "C#"); Exercise fitted = new Exercise("fitted", "html"); Exercise pushups = new Exercise("pushups", "athletics"); Cohort cohort36 = new Cohort("Cohort 36"); Cohort cohort37 = new Cohort("Cohort 37"); Cohort cohort38 = new Cohort("Cohort 38"); Student willy = new Student("Willy", "Metcalf", "sw3k", cohort37); Student audrey = new Student("Audrey", "Borgra", "audbor", cohort37); Student kevin = new Student("Kevin", "Kevinson", "kev.dev", cohort37); Student james = new Student("James", "Nitz", "nitzle", cohort37); Student cooper = new Student("Cooper", "Cooperson", "coop", cohort38); Student slacker = new Student("slacker", "Slackerson", "slack", cohort38); Student john = new Student("john", "johnson", "jj", cohort36); Instructor rose = new Instructor("rose", "roseington", "roseallday", cohort37, "fashion"); Instructor chortle = new Instructor("Steve", "Brownlee", "chortlehoort", cohort37, "dad jokes"); Instructor mo = new Instructor("mo", "money", "momo", cohort37, "making cheesecake"); Instructor andy = new Instructor("andy", "anderson", "slackhandle1", cohort38, "coding"); List <Instructor> instructorList = new List <Instructor>() { rose, chortle, mo, andy }; List <Cohort> cohortList = new List <Cohort>() { cohort37, cohort36, cohort37 }; cohort36.addStudent(john); cohort37.addStudent(willy); cohort37.addStudent(audrey); cohort37.addStudent(kevin); cohort37.addStudent(james); cohort37.addInstructor(rose); cohort37.addInstructor(chortle); cohort37.addInstructor(mo); cohort38.addInstructor(andy); chortle.assignExercise(james, planner); chortle.assignExercise(james, nutshell); rose.assignExercise(kevin, fitted); rose.assignExercise(kevin, nutshell); mo.assignExercise(willy, holidayroad); mo.assignExercise(willy, nutshell); mo.assignExercise(willy, pushups); rose.assignExercise(audrey, planner); rose.assignExercise(audrey, fitted); studentsList.Add(willy); studentsList.Add(audrey); studentsList.Add(james); studentsList.Add(kevin); studentsList.Add(cooper); studentsList.Add(slacker); studentsList.Add(john); exercisesList.Add(nutshell); exercisesList.Add(holidayroad); exercisesList.Add(fitted); exercisesList.Add(planner); foreach (Exercise exercise in exercisesList) { Console.WriteLine($"-------{exercise.Name}-------"); foreach (Student student in studentsList) { foreach (Exercise singleExercise in student.Exercises) { if (singleExercise.Name == exercise.Name) { Console.WriteLine($"{student.FirstName} {student.LastName}"); Console.WriteLine($" "); } } } } //List JAVASCRIPT EXERCISES var javascriptExercises = exercisesList.Where(exercise => { return(exercise.Language == "javascript"); }).ToList(); foreach (var exercise in javascriptExercises) { Console.WriteLine($"{exercise.Name} is written in JavaScript"); } //List students in a particular cohort EXERCISES var cohort38Students = studentsList.Where(student => { return(student.Cohort == cohort38); }).ToList(); foreach (var student in cohort38Students) { Console.WriteLine($"{student.FirstName} is in Cohort 38!"); } //List instructors in a particular cohort EXERCISES var instructorsInCohort38 = instructorList.Where(instructor => { return(instructor.Cohort == cohort38); }).ToList(); foreach (var instructor in instructorsInCohort38) { Console.WriteLine($"{instructor.FirstName} is in Cohort 38!"); } //Sort students by last name var studentsSortedByLastName = studentsList.OrderBy(student => student.LastName).ToList(); foreach (var student in studentsSortedByLastName) { Console.WriteLine($"{student.FirstName} {student.LastName}"); } //students not working on anything var studentsNotWorking = studentsList.Where(student => { return(student.Exercises == null || student.Exercises.Count() == 0); }); foreach (var student in studentsNotWorking) { Console.WriteLine($"{student.FirstName} {student.LastName} isnt working on anything"); } //Sort students by who's doing the most exercise var overAchiever = studentsList.OrderByDescending(student => student.Exercises.Count()).ToList().FirstOrDefault(); Console.WriteLine($"{overAchiever.FirstName} {overAchiever.LastName} has the most exercises "); var groups = studentsList.GroupBy(student => student.Cohort.Name); foreach (var group in groups) { Console.WriteLine($"There are {group.Count()} in {group.Key}"); } }
public Instructor(string firstName, string lastName, string slack, string specialty, Cohort cohort) { FirstName = firstName; LastName = lastName; SlackHandle = slack; Cohort = cohort; Specialty = specialty; }
public List <Student> GetAllStudents() { List <Student> students = new List <Student>(); using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @"SELECT s.Id, s.FirstName, s.LastName, s.SlackHandle, s.CohortId, c.Name AS CohortName, + e.Id AS ExerciseId, e.Language, e.Name FROM Student s INNER JOIN Cohort c On s.CohortId = c.Id INNER JOIN StudentExercise se ON se.StudentId = s.Id INNER JOIN Exercise e ON se.ExerciseId = e.Id"; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int idColumnPosition = reader.GetOrdinal("Id"); int idValue = reader.GetInt32(idColumnPosition); int firstNameColumnPosition = reader.GetOrdinal("FirstName"); string firstNameValue = reader.GetString(firstNameColumnPosition); int lastNameColumnPosition = reader.GetOrdinal("LastName"); string lastNameValue = reader.GetString(lastNameColumnPosition); int slackHandleColumnPosition = reader.GetOrdinal("SlackHandle"); string slackHandleValue = reader.GetString(slackHandleColumnPosition); int cohortsIdColumnPosition = reader.GetOrdinal("CohortId"); int cohortsId = reader.GetInt32(cohortsIdColumnPosition); int cohortsNameColumnPosition = reader.GetOrdinal("CohortName"); string cohortsName = reader.GetString(cohortsNameColumnPosition); int exerciseIdColumnPosition = reader.GetOrdinal("ExerciseId"); int exerciseId = reader.GetInt32(exerciseIdColumnPosition); int exerciseNameColumnPosition = reader.GetOrdinal("Name"); string exerciseName = reader.GetString(exerciseNameColumnPosition); int exerciseLanguageColumnPosition = reader.GetOrdinal("Language"); string exerciseLanguage = reader.GetString(exerciseLanguageColumnPosition); Cohort newCohort = new Cohort(cohortsId, cohortsName); Student newStudent = new Student(idValue, firstNameValue, lastNameValue, slackHandleValue, newCohort); List <Exercise> exercises = new List <Exercise>(); Exercise newExercise = new Exercise(exerciseId, exerciseName, exerciseLanguage); exercises.Add(newExercise); newStudent.Exercises = exercises; students.Add(newStudent); } reader.Close(); return(students); } } }
static void Main(string[] args) { Cohort cohort32 = new Cohort("Cohort 32"); Cohort cohort33 = new Cohort("Cohort 33"); Cohort cohort34 = new Cohort("Cohort 34"); Cohort cohort35 = new Cohort("Cohort 35"); Student student1 = new Student("Nick", "Wessel", "wesseln1", cohort32); Student student2 = new Student("Dave", "Cornish", "heidi1", cohort32); Student student3 = new Student("Heidi", "Smith", "smith1", cohort32); Student student4 = new Student("Mark", "McCann", "mccann1", cohort33); Student student5 = new Student("Seth", "Williams", "willIam", cohort34); Student student6 = new Student("Keaton", "Heights", "higherThanKeaton", cohort34); Student student7 = new Student("Phil", "Philly", "PhillyPhil", cohort35); Student student8 = new Student("Stephan", "Walgreens", "Walgreens1", cohort35); Student student9 = new Student("James", "Kay", "KayJames", cohort35); Instructor AdamSheaffer = new Instructor("Adam", "Sheaffer", "adam-sheaffer", "back-end", cohort32); Instructor BrendaLong = new Instructor("Brenda", "Long", "brenda-long", "front-end", cohort33); Instructor MoSilvera = new Instructor("Mo", "Silvera", "mo-silvera", "front-end", cohort34); Instructor MadiPiper = new Instructor("Mady", "Piper", "madi-piper", "back-end", cohort35); Exercise exercise1 = new Exercise("Create a for each loop.", "JS"); Exercise exercise2 = new Exercise("Stylize the index.", "CSS"); Exercise exercise3 = new Exercise("Develop an app.", "React"); Exercise exercise4 = new Exercise("Build a website.", "HTML"); Exercise exercise5 = new Exercise("Study If Else stataments", "JS"); List <Student> students = new List <Student>() { student1, student2, student3, student4, student5, student6, student7, student8, student9 }; List <Cohort> cohorts = new List <Cohort>() { cohort32, cohort33, cohort34, cohort35 }; List <Instructor> instructors = new List <Instructor>() { AdamSheaffer, BrendaLong, MadiPiper, MoSilvera }; List <Exercise> exercises = new List <Exercise>() { exercise1, exercise2, exercise3, exercise4, exercise5 }; cohort32.CohortStudents.Add(student1); cohort32.CohortStudents.Add(student2); cohort32.CohortStudents.Add(student3); cohort33.CohortStudents.Add(student4); cohort34.CohortStudents.Add(student5); cohort34.CohortStudents.Add(student6); cohort35.CohortStudents.Add(student7); cohort35.CohortStudents.Add(student8); cohort35.CohortStudents.Add(student9); cohort32.CohortInstructors.Add(AdamSheaffer); cohort33.CohortInstructors.Add(BrendaLong); cohort34.CohortInstructors.Add(MoSilvera); cohort35.CohortInstructors.Add(MadiPiper); AdamSheaffer.AssignExercise(student1, exercise5); AdamSheaffer.AssignExercise(student1, exercise3); AdamSheaffer.AssignExercise(student2, exercise1); AdamSheaffer.AssignExercise(student3, exercise1); BrendaLong.AssignExercise(student4, exercise2); MoSilvera.AssignExercise(student5, exercise3); MoSilvera.AssignExercise(student6, exercise3); MadiPiper.AssignExercise(student7, exercise4); MadiPiper.AssignExercise(student8, exercise4); Console.WriteLine(); Console.WriteLine("Student Reports"); foreach (var student in students) { Console.WriteLine($"Student: {student.FirstName} {student.LastName}"); Console.WriteLine($"From: {student.Cohort.Name}"); Console.WriteLine(); foreach (var exercise in student.StudentExercises) { Console.WriteLine($"Exercise: {exercise.Name}"); Console.WriteLine($"Language: {exercise.Language}"); Console.WriteLine(); } List <Exercise> javaScriptExercises = exercises.Where(exercise => exercise.Language == "JS").ToList(); foreach (var exercise in javaScriptExercises) { Console.WriteLine($"{exercise.Name} is a {exercise.Language} language!"); } List <Student> cohortStudents = students.Where(student => student.Cohort.Name == "Cohort 35").ToList(); Console.WriteLine($"Cohort Student List: "); Console.WriteLine(); foreach (var cohortStudent in cohortStudents) { Console.WriteLine($"{cohortStudent.FirstName} {cohortStudent.LastName}"); Console.WriteLine(); } List <Instructor> cohortInstructors = instructors.Where(instructor => instructor.Cohort.Name == "Cohort 35").ToList(); Console.WriteLine($"Instructor: "); foreach (var cohortInstructor in cohortInstructors) { Console.WriteLine($"{cohortInstructor.FirstName} {cohortInstructor.LastName}"); Console.WriteLine(); } var orderedStudnetList = students.OrderBy(student => student.LastName); foreach (var s in orderedStudnetList) { Console.WriteLine($"{s.LastName}, {s.FirstName}"); } Console.WriteLine(); var noExercises = students.Where(student => student.StudentExercises.Count == 0); Console.WriteLine("Currently no exercises assigned:"); foreach (var s in noExercises) { Console.WriteLine($"{s.FirstName} {s.LastName}"); } var studentWithMostExercises = students.Select(student => new { firstName = student.FirstName, lastName = student.LastName, numberOfExercises = student.StudentExercises.Count() }).OrderByDescending(ex => ex.numberOfExercises).FirstOrDefault(); Console.WriteLine(); Console.WriteLine($"{studentWithMostExercises.firstName} {studentWithMostExercises.lastName} has the most active assignments!"); foreach (var cohort in cohorts) { Console.WriteLine(); Console.WriteLine($"{cohort.Name}:"); Console.WriteLine($"{cohort.CohortStudents.Count}"); } } }
static void Main(string[] args) { Exercise exercise1 = new Exercise("Create a for each loop.", "JS"); Exercise exercise2 = new Exercise("Stylize the index.", "CSS"); Exercise exercise3 = new Exercise("Develop an app.", "React"); Exercise exercise4 = new Exercise("Build a website.", "HTML"); Exercise exercise5 = new Exercise("Study If Else stataments", "JS"); Cohort cohort1 = new Cohort("Cohort 33"); Cohort cohort2 = new Cohort("Cohort 34"); Cohort cohort3 = new Cohort("Cohort 35"); Student FortunatoMugnano = new Student("Fortunato", "Mugnano", "fortunato-mugnano", cohort1); Student DavidCornish = new Student("David", "Cornish", "david-cornish", cohort2); Student HeidiSmith = new Student("Heidi", "Smith", "heidi-smith", cohort3); Student PhilGrass = new Student("Phil", "Grass", "phil-grass", cohort3); Student MarkLong = new Student("Mark", "Long", "mark-long", cohort1); Student NickRiviera = new Student("Nick", "Riviera", "nick-riviera", cohort2); Instructor AdamSheaffer = new Instructor("Adam", "Sheaffer", "adam-sheaffer", "back-end", cohort1); Instructor BrendaLong = new Instructor("Brenda", "Long", "brenda-long", "front-end", cohort2); Instructor MoSilvera = new Instructor("Mo", "Silvera", "mo-silvera", "front-end", cohort3); Instructor MadyPiper = new Instructor("Mady", "Piper", "madi-piper", "back-end", cohort3); cohort1.StudentList.Add(FortunatoMugnano); cohort1.StudentList.Add(MarkLong); cohort2.StudentList.Add(DavidCornish); cohort3.StudentList.Add(HeidiSmith); cohort3.StudentList.Add(PhilGrass); cohort2.StudentList.Add(NickRiviera); cohort1.InstructorList.Add(AdamSheaffer); cohort2.InstructorList.Add(BrendaLong); cohort3.InstructorList.Add(MoSilvera); cohort3.InstructorList.Add(MadyPiper); AdamSheaffer.AssignExercise(FortunatoMugnano, exercise1); BrendaLong.AssignExercise(DavidCornish, exercise2); MoSilvera.AssignExercise(HeidiSmith, exercise3); AdamSheaffer.AssignExercise(PhilGrass, exercise4); AdamSheaffer.AssignExercise(FortunatoMugnano, exercise5); List <Student> students = new List <Student>(); students.Add(FortunatoMugnano); students.Add(DavidCornish); students.Add(HeidiSmith); students.Add(PhilGrass); students.Add(MarkLong); students.Add(NickRiviera); List <Exercise> exercises = new List <Exercise>(); exercises.Add(exercise1); exercises.Add(exercise2); exercises.Add(exercise3); exercises.Add(exercise4); exercises.Add(exercise5); foreach (Student student in students) { Console.WriteLine($"Student: {student._firstName} {student._lastName}"); Console.WriteLine("Exercises:"); foreach (Exercise exercise in student.Exercises) { Console.WriteLine($"Program: {exercise.Name} Language: {exercise.Language}"); } } List <Cohort> cohorts = new List <Cohort>() { cohort1, cohort2, cohort3, }; List <Instructor> instructor = new List <Instructor>() { AdamSheaffer, MoSilvera, BrendaLong, MadyPiper }; List <Exercise> javascriptExercise = exercises.Where(ex => ex.Language == "JS").ToList(); foreach (var item in javascriptExercise) { Console.WriteLine(item.Name); } var listOfStudentsInCohort = cohorts.Where(cohort => cohort.Name == "Cohort 35") .SelectMany(c => c.StudentList).Distinct().ToList(); foreach (var item in listOfStudentsInCohort) { Console.WriteLine($"{item._firstName} {item._lastName} is in Cohort 35"); } var listOfInstructors = cohorts.Where(c => c.Name == "Cohort 35").SelectMany(c => c.InstructorList).Distinct().ToList(); foreach (var item2 in listOfInstructors) { Console.WriteLine($"{item2._firstName} {item2._lastName}: Instructors assigned for cohort-35"); } var studentsByLastName = students.OrderBy(x => x._lastName).ToList(); foreach (var item3 in studentsByLastName) { Console.WriteLine(item3._lastName); } var studentWithoutExercises = students.Where(student => student.Exercises.Count == 0).ToList(); foreach (var item4 in studentWithoutExercises) { Console.WriteLine($"These student does't have any exercise assigned: {item4._firstName} {item4._lastName}"); } var studentWithMostExercises = students.Select(student => new { firstName = student._firstName, lastName = student._lastName, numberOfExercises = student.Exercises.Count() }).OrderByDescending(x => x.numberOfExercises).FirstOrDefault(); Console.WriteLine($"The student with the most exercises: {studentWithMostExercises.firstName} {studentWithMostExercises.lastName} with {studentWithMostExercises.numberOfExercises} exercises"); var numOfStudents = cohorts.Select(x => new { name = x.Name, numOfStudentsInCohort = x.StudentList.Count() }).ToList(); foreach (var item5 in numOfStudents) { Console.WriteLine($"In {item5.name} there are {item5.numOfStudentsInCohort} students."); } }
static void Main(string[] args) { var ExerciseList = new List <Exercise>(); var FizzBuzz = new Exercise("Fizz Buzz", "JavaScript"); var Journal = new Exercise("Journal", "HTML"); var DiamondCutter = new Exercise("Diamond Cutter", "Ruby"); var GetYourGlasses = new Exercise("Get Your Glasses", "C#"); var Day32 = new Cohort("Day Cohort 32"); var Night10 = new Cohort("Night Cohort 10"); var Day13 = new Cohort("Day Cohort 13"); var Bryan = new Student("Bryan", "Nilsen", "@BryanNilsen", "Day Cohort 13"); var Ricky = new Student("Ricky", "McConnell", "@Rickydogsickdog", "Day Cohort 32"); var Julian = new Student("Julian", "Swayze", "@Juls", "Night Cohort 10"); var Corey = new Student("Corey", "Trevor", "@CoreyTrevor", "Day Cohort 32"); var Randy = new Student("Randy", "Lahey", "@Randers", "Night Cohort 10"); var Steve = new Instructor("Steve", "Brownlee", "@SteveCoach", "Dad Jokes", "Day Cohort 32"); var Adam = new Instructor("Adam", "Schaeffer", "@AdamShaef", "Snacks", "Day Cohort 13"); var Andy = new Instructor("Andy", "Collins", "@AndyBoBandy", "Dancing", "Night Cohort 10"); Steve.AssignExercise(Ricky, FizzBuzz); Steve.AssignExercise(Bryan, DiamondCutter); Adam.AssignExercise(Corey, GetYourGlasses); Adam.AssignExercise(Julian, Journal); Andy.AssignExercise(Ricky, GetYourGlasses); Andy.AssignExercise(Corey, DiamondCutter); Ricky.ViewAssignedExercises(); Bryan.ViewAssignedExercises(); Julian.ViewAssignedExercises(); Corey.ViewAssignedExercises(); Day13.StudentList.Add(Bryan); Day32.StudentList.Add(Ricky); Day32.StudentList.Add(Corey); Night10.StudentList.Add(Julian); Console.WriteLine("------------------"); foreach (Student student in Day32.StudentList) { Console.WriteLine($"Day Cohort 32: {student.FirstName}"); } Console.WriteLine("------------------"); foreach (Student student in Night10.StudentList) { Console.WriteLine($"Night Cohort 10: {student.FirstName}"); } Console.WriteLine("------------------"); foreach (Student student in Day13.StudentList) { Console.WriteLine($"Day Cohort 13: {student.FirstName}"); Console.WriteLine(""); } var AllStudents = new List <Student>(); AllStudents.Add(Bryan); AllStudents.Add(Ricky); AllStudents.Add(Julian); AllStudents.Add(Corey); AllStudents.Add(Randy); var AllExercises = new List <Exercise>(); AllExercises.Add(FizzBuzz); AllExercises.Add(Journal); AllExercises.Add(DiamondCutter); AllExercises.Add(GetYourGlasses); var AllInstructors = new List <Instructor>(); AllInstructors.Add(Steve); AllInstructors.Add(Adam); AllInstructors.Add(Andy); var AllCohorts = new List <Cohort>(); AllCohorts.Add(Day32); AllCohorts.Add(Day13); AllCohorts.Add(Night10); // List exercises for the JavaScript language by using the Where() LINQ method. List <Exercise> JSExercises = (from exercise in AllExercises where exercise.Language == "JavaScript" select exercise).ToList(); foreach (Exercise exer in JSExercises) { Console.WriteLine($"List of JS exercises: {exer.Name}"); } // List students in a particular cohort by using the Where() LINQ method. List <Student> StudentsInCohort = (from student in AllStudents where student._cohort == "Day Cohort 32" select student).ToList(); foreach (Student stu in StudentsInCohort) { Console.WriteLine($"Students in Day Cohort 32: {stu.FirstName} {stu.LastName}"); } // List instructors in a particular cohort by using the Where() LINQ method. List <Instructor> InstructorInCohort = (from instructor in AllInstructors where instructor._cohort == "Night Cohort 10" select instructor).ToList(); foreach (Instructor inst in InstructorInCohort) { Console.WriteLine($"Instructor of the Cohort: {inst.FirstName} {inst.LastName}"); } // Sort the students by their last name. List <Student> OrderStudent = AllStudents.OrderBy(s => s.LastName).ToList(); foreach (Student stu in OrderStudent) { Console.WriteLine($"All student ordered by last name: {stu.LastName} {stu.FirstName}"); } // Display any students that aren't working on any exercises. var NoExercises = (from student in AllStudents where student.ExerciseList.Count == 0 select student); foreach (Student stu in NoExercises) { Console.WriteLine($"Students with no exercises: {stu.FirstName} {stu.LastName}"); } // Which student is working on the most exercises var MostExercises = AllStudents.OrderByDescending(student => student.ExerciseList.Count()).Take(2); foreach (Student s in MostExercises) { Console.WriteLine($"Student with most exercises: {s.FirstName} {s.LastName}"); } // How many students in each cohort? foreach (var cohort in AllCohorts) { Console.WriteLine($"{cohort.CohortName}: {cohort.StudentList.Count()} students."); } }