/
Program.cs
139 lines (113 loc) · 5.02 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Linq;
namespace StudentExercises
{
class Program
{
static void Main(string[] args)
{
Exercise MartinsAquarium = new Exercise("MartinsAquarium", "JavaScript");
Exercise PlanYourHeist = new Exercise("Plan Your Heist", "C#");
Exercise GlassdalePD = new Exercise("Glassdale PD", "JavaScript");
Exercise Nutshell = new Exercise("Nutshell", "React");
Cohort Day37 = new Cohort("Day Cohort 37");
Cohort Day39 = new Cohort("Day Cohort 39");
Cohort Evening6 = new Cohort("Evening Cohort 6");
Student SpencerT = new Student("Spencer", "Truett", "@Spencer Truett", Day37);
Student DanielF = new Student("Daniel", "Fuqua", "@Daniel Fuqua", Day39);
Student HoldenP = new Student("Holden", "Parker", "@Holden Parker", Day37);
Student MattC = new Student("Matt", "Crook", "@Matt Crook", Evening6);
Student DouieN = new Student("Douie", "Notheen", "@DoesNothing", Evening6);
Instructor AdamS = new Instructor("Adam", "Sheaffer", "@adamsheaf", Day37)
{
Specialty = "Snacks"
};
AdamS.AssignExercise(MartinsAquarium, HoldenP);
AdamS.AssignExercise(GlassdalePD, HoldenP);
AdamS.AssignExercise(Nutshell, HoldenP);
AdamS.AssignExercise(MartinsAquarium, SpencerT);
AdamS.AssignExercise(GlassdalePD, SpencerT);
Instructor MoS = new Instructor("Mo", "Silvera", "@Mo", Day39)
{
Specialty = "Dancing"
};
MoS.AssignExercise(PlanYourHeist, DanielF);
MoS.AssignExercise(Nutshell, DanielF);
Instructor SteveB = new Instructor("Steve", "Brownlee", "@coach", Evening6)
{
Specialty = "Dad Jokes"
};
SteveB.AssignExercise(Nutshell, MattC);
SteveB.AssignExercise(MartinsAquarium, MattC);
var AllStudents = new List<Student>()
{
SpencerT,
DanielF,
HoldenP,
MattC,
DouieN
};
var AllExercises = new List<Exercise>()
{
Nutshell,
MartinsAquarium,
GlassdalePD,
PlanYourHeist
};
var AllInstructors = new List<Instructor>()
{
AdamS,
SteveB,
MoS
};
var AllCohorts = new List<Cohort>()
{
Day37,
Day39,
Evening6
};
foreach (Student student in AllStudents)
{
foreach (Exercise exercise in student.Exercises)
{
Console.WriteLine($"{student.FirstName} is working on the {exercise.Name} {exercise.Language} exercise in {student.Cohort.Name}.");
}
}
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.FirstName} {student.LastName}");
}
var day37Instructors = AllInstructors.Where(instructor => instructor.Cohort == Day37);
foreach (var instructor in day37Instructors)
{
Console.WriteLine($"Instructor in day cohort 37: {instructor.FirstName} {instructor.LastName}");
}
var studentsByLastName = AllStudents.OrderBy(student => student.LastName);
Console.WriteLine("Students ordered by last name:");
foreach (var student in studentsByLastName)
{
Console.Write($"{student.FirstName} {student.LastName} ");
}
var studentsNotWorking = AllStudents.Where(student => student.Exercises.Count() == 0);
foreach (var student in studentsNotWorking)
{
Console.WriteLine($"Students not working on any exercises: {student.FirstName} {student.LastName}");
}
var descendStudentMostExercises = AllStudents.OrderByDescending(student => student.Exercises.Count());
var studentMostExercises = descendStudentMostExercises.First();
Console.WriteLine($"{studentMostExercises.FirstName} {studentMostExercises.LastName} 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}.");
}
}
}
}