Keep the assignment histories, averages, tutoring details, and weekly reservations from your completed Grade Book 2.4. This lesson gives each class control over the collections and state that belong to it.
Update the window Title in MainWindow.xaml from 2.4 to 2.5, retaining your last name. Keep .NET Framework 4.8. Update AssemblyVersion and AssemblyFileVersion in Properties/AssemblyInfo.cs to 2.5.0.0.
Keep the existing using System.Collections.Generic directives in Course.cs and Instructor.cs.
| Class | Old field | New declaration and initializer |
|---|---|---|
| Course | Assignments | private readonly List<Assignment> assignments = new List<Assignment>(); |
| Instructor | Assistants | private readonly List<Instructor> assistants = new List<Instructor>(); |
| Instructor | NumberOfStudentsTutored | private int numberOfStudentsTutored; |
| Assignment | Attempts | private readonly Attempt[] attempts = new Attempt[3]; |
| Assignment | Submission | private Attempt submission; |
| TutoringSchedule | Sessions | private readonly Student[,] sessions = new Student[3, 5]; |
In the class diagram, - means private, + means public, and <<readonly>> means include the C# readonly keyword in the field declaration. Keep the classes themselves public.
Keep its existing null check, first-match break, and null result when no matching type exists.
Keep its first suitable assistant result, knowledge comparison, null check, and break.
Keep the existing guards, capped knowledge gain, and RequiredSessions decrement.
Change the stored history reference to this.attempts and the best passing submission field references to this.submission. The submission parameter still names the incoming attempt; keep the this prefix when referring to the field.
Use this.attempts for Length and indexing. Keep the first empty index result and -1 when all three slots are occupied.
Read this.attempts in the existing indexed loop. Keep its comparison and null result for an empty history.
Read this.attempts for the existing three-slot display. Keep Available, the letter grades, best accuracy, average accuracy, and line breaks.
Traverse this.attempts. Keep the existing initialized locals, null filtering, count > 0 guard, and returned average.
Keep the invalid-location and empty-cell guards, the two separate reservation-retained messages, the successful-session update, and the final feedback.
Keep the return codes, occupied-cell check, zero-required-sessions check, same-day search, and selected-cell assignment.
Keep both guards and clear only the selected occupied cell.
Keep the foreach reference comparison and count only cells referring to the supplied non-null student.
Keep the period and weekday loops, row labels, [ ] and [X] cells, and line breaks.
Keep the location check, null return for an invalid location, and selected-cell reference return.
Keep the existing bounds expression and both GetLength dimensions.
Keep the method's existing Course parameter and private void signature. The two history event handlers already call this method and keep their current guards.
Use the public operations shown in the controlled-access class diagram. Preserve the configured objects, values, and creation confirmation.
Follow the controlled-access class diagram and keep the existing Canvas objects, setup values, and schedule display refresh.
The existing buttons and Click names stay in MainWindow.xaml. Keep the tutoring handlers, complete-tutoring feedback, attendance details, and their GetTutoringDetails calls.
Before clicking New Blackboard, add the following Watch expressions. Some are unavailable outside the method; unavailable means out of scope, not null.
| Expression | What to observe inside Course.AddAssignment |
|---|---|
| this | The Web Design Course receiving the assignment |
| assignment | The current Assignment parameter |
| this.assignments.Count | 0 before adding Plan, then 1 after the Add statement |
| assignment.Name | Plan on the first call |
The highlighted if has not executed yet. Here this is the Course, not MainWindow. Use F10 until the Add statement is highlighted; it has not executed while highlighted. Press F10 to execute that statement, then confirm Count is 1 and entry [0] refers to the same object as assignment. Depending on debugger sequence points, stepping may also pause on a brace. On the next two calls the names are HTML Exercises and Website 1.
Blackboard created. appears in the status area. Do not call AddAssignment or change collection contents through Watch.
These are source traces, not extra UI actions. The supplied creation buttons do not send these invalid requests.
| Request | Condition result | Stored entries |
|---|---|---|
| AddAssignment(null) | false | Unchanged |
| AddAssignment with the same stored reference again | false | Unchanged |
| AddAssistant(null) | false | Unchanged |
| AddAssistant with the receiving instructor itself | false | Unchanged |
| AddAssistant with the same stored reference again | false | Unchanged |
The Plan and Website 1 histories still have three Available slots. HTML Exercises has three completed attempts. Its best accuracy is 84.58% and its average accuracy is 82.08%. A fourth Take midterm click reports that the assignment or instructor is unavailable, or all three attempts have been used; the history remains unchanged.
Expect Tutoring session completed. Sheldon is the selected tutor with knowledge level 75.3; Arthur's knowledge is 70.5 and two required sessions remain. The tutor details remain part of the existing feedback.
The first booking shows [X] and Samantha reservations: 1. Attendance uses Jeff, raises Samantha's knowledge from 87.8 to 92.8, reduces required sessions to 3, clears the cell, and refreshes the reservation count to 0. The feedback still includes the tutor and student knowledge levels.
Two sessions complete: Samantha reaches knowledge 95 with two required sessions remaining. The existing completion feedback explains that no tutor has a higher knowledge level. Direct tutoring leaves the reservation in place. Click Attend: it reports No tutor has a higher knowledge level. Reservation retained. The cell stays [X] and the count stays 1. Cancel reservation clears it; a second cancellation reports that no reservation was canceled.
The fourth click reports No tutoring sessions are required. Arthur remains at knowledge 80.3 with zero required sessions. This is distinct from the no-more-knowledge outcome in Canvas.