private static void Main(string[] args) { // Declare and init the extended console framework I am working on ExtConsole console = new ExtConsole("Lab 4 - David J Richer"); // Write the console header to the buffer console.WriteTitle(); console.Write(console.CenteredString("This is a student registration service")); console.LineBreak(); console.Print(); // Main Program Loop do { // Get the student name string studentName = console.ReadANonEmptyString("Enter Student Name"); // Create the student object Student student = new Student(studentName); // Init the loop check for inner loop bool innerLoop = true; // Inner loop for course selection do { // Reinit the counter int courseCounter = 0; // Output the course selections console.WriteHeader("Course Selection"); foreach (Course course in Courses) { console.Write(String.Format("Enter {0} to select {1} ", courseCounter, course.Title)); console.WriteLine( String.Format("Seats: {0}", (Courses[courseCounter].MaxEnrollment - Courses[courseCounter].CurrentlyEnrolled)), ConsoleColor.Yellow); courseCounter++; } console.WriteLine(String.Format("Enter {0} to finish with this student", courseCounter)); console.LineBreak(); console.Print(); // Get the course selection // Users will not be able to enter a number out of bounds of the selection int courseSelection; do { courseSelection = console.ReadAValidatedInt("Enter your selection"); console.LineBreak(); console.Print(); } while (courseSelection > courseCounter); // Try to add the student to the course, filtering through each response // from student.AddCourse if (courseSelection == courseCounter) innerLoop = false; else { switch (student.AddCourse(Courses[courseSelection])) { case Student.AddCourseResults.AlreadyEnrolled: // Already Enrolled console.WriteAErrorLine(String.Format("The student is already enrolled in {0} - {1}", Courses[courseSelection].Code, Courses[courseSelection].Title)); break; case Student.AddCourseResults.OverHours: // To many hours console.WriteAErrorLine( "The course hours exceed the available hours in the students schedule"); break; case Student.AddCourseResults.Added: // Mission success, also associate the student with the course if (Courses[courseSelection].AddStudent(student)) { console.WriteHeader("Student Information"); console.WriteLine(String.Format("Student Name: {0}\t", student.Name)); console.WriteLine(String.Format("{0}\t{1}", Courses[courseSelection].Code, Courses[courseSelection].Title)); console.WriteLine( String.Format("Current weekly hours: {0}\t\tCurrent Tuition Fees: {1:C2}", student.CurrentEnrolledHours, student.CurrentTutionCosts)); console.LineBreak(); console.Print(); } else { console.WriteAErrorLine(String.Format("{0} - {1} is full", Courses[courseSelection].Code, Courses[courseSelection].Title)); student.DelCourse(Courses[courseSelection]); } break; } } } while (innerLoop); } while (console.ReadYesOrNo("Would you like to add another student")); // Print the finall course enrollments console.WriteHeader("Final course enrollment statistics"); foreach (Course course in Courses) { console.WriteLine(String.Format("Course {0}, {1}", course.Code, course.Title)); foreach (string name in course.StudentList) console.Write(String.Format("{0}\t", name)); console.LineBreak(2); } console.Pause(); }
// Add a student to the list if the course has available enrollent public bool AddStudent(Student student) { // Immediatley return false if the course is full if (IsAvailable) return false; // Otherwise, add the student and then return true _students.Add(student); return true; }