2.5 Grade Book Assignment [2 hours 15 minutes]

Grade Book 2.5 — Protect the Collections

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.

The estimates cover task work, including nested instructions, diagram interpretation, implementation, checks, and the explicitly assigned debugger work. Linked readings and videos and unplanned troubleshooting are excluded. These approximate planning guides may vary by student.

1.Copy the previous version [5 minutes]
A Copy your completed Grade Book 2.4 folder, rename the copy and solution for Grade Book 2.5 using your last name, open the copied solution, and restore NuGet packages

In MainWindow.xaml, update the window title 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.

Current Grade Book 2.4 structure before encapsulation. Object-reference fields are shown only on arrows with visibility; Complete generic types identify lists and brackets show fixed array dimensions. Operations use one compartment; this lesson adds no constructors or properties.
Starting structure — your completed Grade Book 2.4
Keep valid assignments and assistants
2.Make the collection fields private [10 minutes]
A Use the focused diagram and table to revise the fields in their declaring classes

Keep the existing using System.Collections.Generic; directives in Course.cs and Instructor.cs.

Fields controlled by their own class
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.

Focused 2.5 encapsulation changes. Italic pen badges identify changed private fields; bold plus badges identify new public methods. Public GetTutor remains callable by MainWindow. Object-reference fields are shown only on arrows with visibility; Complete generic types identify lists and brackets show fixed array dimensions. Operations use one compartment; this lesson adds no constructors or properties.
Fields and public operations for controlled access
3.Course.AddAssignment — Register an assignment [10 minutes]
A In Course.cs, add AddAssignment using the focused signature and activity diagram
AddAssignment adds a non-null reference only when the private assignment list does not contain that reference. Both outcomes end the method.
Add an assignment through its course
4.Instructor.AddAssistant — Register an assistant [10 minutes]
A In Instructor.cs, add AddAssistant using the focused signature and activity diagram
AddAssistant rejects null, the current instructor object, and references already present in the private assistant list.
Keep null, self, and duplicate references out of the assistant list
5.Update the searches and tutoring count [5 minutes]
A Course.GetAssignmentByType — Search the private list
1 In Course.cs, update GetAssignmentByType to use this.assignments for Count, indexing, and the returned matching entry

Keep its existing null check, first-match break, and null result when no matching type exists.

B Instructor.GetAssistantByKnowledgeLevel — Search the private list
1 In Instructor.cs, change the foreach source in GetAssistantByKnowledgeLevel to this.assistants

Keep its first suitable assistant result, knowledge comparison, null check, and break.

C Instructor.TutorStudent — Own the tutoring count
1 In Instructor.cs, update TutorStudent to increment this.numberOfStudentsTutored after a successful session

Keep the existing guards, capped knowledge gain, and RequiredSessions decrement.

Keep the same learning records and reservations
6.Update the attempt-history field references [10 minutes]
A Assignment.Submit — Use the private attempt state
1 In Assignment.cs, update Submit for the renamed private fields

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.

B Assignment.FindAvailableAttempt — Use the private attempt state
1 In Assignment.cs, update FindAvailableAttempt for the renamed private fields

Use this.attempts for Length and indexing. Keep the first empty index result and -1 when all three slots are occupied.

C Assignment.GetBestAttempt — Use the private attempt state
1 In Assignment.cs, update GetBestAttempt for the renamed private fields

Read this.attempts in the existing indexed loop. Keep its comparison and null result for an empty history.

D Assignment.GetAttemptHistory — Use the private attempt state
1 In Assignment.cs, update GetAttemptHistory for the renamed private fields

Read this.attempts for the existing three-slot display. Keep Available, the letter grades, best accuracy, average accuracy, and line breaks.

E Assignment.GetAverageAccuracy — Use the private attempt state
1 In Assignment.cs, update GetAverageAccuracy for the renamed private fields

Traverse this.attempts. Keep the existing initialized locals, null filtering, count > 0 guard, and returned average.

7.Update the schedule field references [10 minutes]
A TutoringSchedule.Attend — Use the private schedule
1 In TutoringSchedule.cs, update Attend to use this.sessions wherever it currently uses this.Sessions

Keep the invalid-location and empty-cell guards, the two separate reservation-retained messages, the successful-session update, and the final feedback.

B TutoringSchedule.Book — Use the private schedule
1 In TutoringSchedule.cs, update Book to use this.sessions wherever it currently uses this.Sessions

Keep the return codes, occupied-cell check, zero-required-sessions check, same-day search, and selected-cell assignment.

C TutoringSchedule.Cancel — Use the private schedule
1 In TutoringSchedule.cs, update Cancel to use this.sessions wherever it currently uses this.Sessions

Keep both guards and clear only the selected occupied cell.

D TutoringSchedule.CountBookings — Use the private schedule
1 In TutoringSchedule.cs, update CountBookings to use this.sessions wherever it currently uses this.Sessions

Keep the foreach reference comparison and count only cells referring to the supplied non-null student.

E TutoringSchedule.GetDisplay — Use the private schedule
1 In TutoringSchedule.cs, update GetDisplay to use this.sessions wherever it currently uses this.Sessions

Keep the period and weekday loops, row labels, [ ] and [X] cells, and line breaks.

F TutoringSchedule.GetStudent — Use the private schedule
1 In TutoringSchedule.cs, update GetStudent to use this.sessions wherever it currently uses this.Sessions

Keep the location check, null return for an invalid location, and selected-cell reference return.

G TutoringSchedule.IsValidLocation — Use the private schedule
1 In TutoringSchedule.cs, update IsValidLocation to use this.sessions wherever it currently uses this.Sessions

Keep the existing bounds expression and both GetLength dimensions.

Read the complete history through the course
8.Course.GetAssignmentHistory — Assemble the history [15 minutes]
A In Course.cs, add GetAssignmentHistory using the focused signature and activity diagram
Course GetAssignmentHistory traverses its private assignment list, appends each complete attempt history and two line breaks, and returns the combined text.
Course assembles histories from its private list
9.MainWindow.DisplayAssignmentHistories — Display the returned history [5 minutes]
A In MainWindow.xaml.cs, replace the list traversal inside DisplayAssignmentHistories with the single display call in the activity diagram

Keep its existing signature, private void DisplayAssignmentHistories(Course course). The two history event handlers already call this method and keep their current guards.

MainWindow delegates history assembly to Course and displays its returned string.
Delegate history assembly to Course
The existing Blackboard history button calls MainWindow, which asks Course for its privately stored assignment histories. Each Assignment supplies its existing history and average.
The existing history button now reads the private list through Course
10.Connect the creation event handlers to the new methods [10 minutes]
A In MainWindow.xaml.cs, update newBlackboardButton_Click using the diagrams

Use the public operations shown in the controlled-access class diagram. Preserve the configured objects, values, and creation confirmation.

Blackboard creation uses Course.AddAssignment for the configured plan, midterm and final, then Instructor.AddAssistant for the first and second assistants. Existing object setup and creation feedback remain.
Blackboard creation — register through public methods
B In MainWindow.xaml.cs, update newCanvasButton_Click using the diagrams

Follow the controlled-access class diagram and keep the existing Canvas objects, setup values, and schedule display refresh.

Canvas creation uses Course.AddAssignment for the configured plan, midterm and final, then Instructor.AddAssistant for the first and second assistants. Existing object setup and creation feedback remain. Schedule instantiation initializes its private sessions array; MainWindow keeps its display refresh.
Canvas creation — register through public methods and retain its schedule
C Select Build > Build Solution, open the Error List, and resolve any remaining references to the old public collection fields

The existing buttons and Click names stay in MainWindow.xaml. Keep the tutoring handlers, complete-tutoring feedback, attendance details, and their GetTutoringDetails calls.

11.Follow a request into a private collection [15 minutes]
A Check Your Work
1 Stop debugging, then set a breakpoint in Course.cs on if (assignment != null && !this.assignments.Contains(assignment)) inside AddAssignment

Press F5 to start debugging. Click New Blackboard to reach the first call before taking assignments or tutoring. The highlighted statement has not executed. Here this refers to the course, not the window.

2 Open Debug > Windows > Watch > Watch 1 while paused and inspect the starting registration state

Add this.Name, assignment.Name, this.assignments.Count, and this.assignments[0] == assignment to Watch. At this first pause, the names are Web Design and Plan, and the count is 0. The indexed comparison cannot be evaluated until an entry exists; an unavailable expression is not a null reference.

3 Step with F10 until this.assignments.Add(assignment); is highlighted, then press F10 to execute it

Confirm this.assignments.Count is 1 and this.assignments[0] == assignment is true. The list entry and parameter refer to the same object; equal names alone would not prove that relationship.

4 Remove the breakpoint and press F5 to finish creation

Confirm Blackboard created. appears in the status area before clicking another control. Remove the Watch expressions. Do not call registration methods or change collection contents through Watch.

B Use the registration diagrams to trace rejected requests from the source

Open Course.AddAssignment and Instructor.AddAssistant. These are source traces, not UI tests: the creation buttons do not send these invalid requests. For each row, start with the stated object already registered where required. Follow short-circuit evaluation to show why the addition is skipped.

Rejected registration source traces
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
12.Verify histories and tutoring [20 minutes]
A Check Your Work
1 Stop debugging, restart the application with F5, click New Blackboard, then click Take midterm three times and Show Blackboard attempt history

Do not tutor or take another assignment first. Confirm HTML Exercises has three completed attempts. Its displayed best accuracy is 84.58% and average accuracy is 82.08%. These rounded displays represent calculated double values of approximately 84.575 and 82.075.

2 In the same displayed history, inspect Plan and Website 1

Confirm each still has three Available slots. Neither assignment was taken in this case.

3 Continue the same case by clicking Take midterm once more

Confirm The assignment or its instructor is unavailable, or all three attempts have been used. appears. Click Show Blackboard attempt history and confirm the three completed entries and both summary displays are unchanged. The preceding three successful attempts distinguish the full-history path in this case.

4 Click New Blackboard to reset Arthur, then click Tutor Arthur once without taking an assignment first

Confirm Tutoring session completed. appears with Sheldon as tutor, tutor knowledge 75.3, Arthur knowledge 70.5, and Required sessions remaining: 2. The calculated student knowledge is approximately 70.5.

5 Click New Canvas, select Monday in Day: and 1 in Period:, then click Book selected student

Do not tutor or take an assignment before booking. Confirm the Monday period 1 cell is [X] and the schedule displays Samantha reservations: 1.

6 Continue this booking case by clicking Attend

Confirm the feedback identifies Jeff with knowledge 95, Samantha with knowledge 92.8, and Required sessions remaining: 3. Samantha's calculated knowledge is approximately 92.8. Confirm the Monday period 1 cell becomes [ ] and the schedule displays Samantha reservations: 0.

7 Click New Canvas to reset Samantha, select Monday and period 1, click Book selected student, then click Complete Samantha tutoring

Confirm Samantha completed 2 tutoring session(s)., No tutor has a higher knowledge level., Samantha knowledge 95, and Required sessions remaining: 2. Her calculated knowledge is approximately 95. Confirm the Monday period 1 cell remains [X] and the reservation count remains Samantha reservations: 1. Direct tutoring preserves the reservation.

8 Continue the retained-reservation case by clicking Attend

Confirm No tutor has a higher knowledge level. Reservation retained. appears. Samantha's displayed knowledge remains 95, required sessions remain 2, the selected cell stays [X], and the count remains Samantha reservations: 1.

9 Continue the same case by clicking Cancel reservation

Confirm Reservation canceled., an empty Monday period 1 cell, and Samantha reservations: 0.

10 Click Cancel reservation again without booking another reservation

Confirm No reservation was canceled. Select an occupied weekday and period. appears. The cell remains empty and the reservation count remains zero.

11 Click New Blackboard to reset Arthur, then click Tutor Arthur three times without taking an assignment

Confirm Arthur's displayed knowledge is 80.3 and Required sessions remaining: 0. His calculated knowledge is approximately 80.3.

12 Continue Arthur's case by clicking Tutor Arthur once more

Confirm No tutoring sessions are required. appears. Arthur's displayed knowledge remains 80.3 and required sessions remain 0. This follows the zero-required-sessions guard, whereas the Canvas case retained two required sessions when no tutor could increase knowledge.

13.Review the completed structure [5 minutes]
A Use the ending diagram to explain which class owns each list or array and which public methods the other classes can call
Grade Book 2.5 structure. Italic pen badges identify modified members; bold plus badges identify new methods. Arrays remain three attempts and a three-by-five schedule. Object-reference fields are shown only on arrows with visibility; Complete generic types identify lists and brackets show fixed array dimensions. Operations use one compartment; this lesson adds no constructors or properties.
Ending structure — private state and controlled public methods
14.Submit your completed Grade Book 2.5 [5 minutes]
A Select Build > Build Solution, open the Error List, and check the applicable StyleCop feedback
B Zip your completed solution, submit it to the Feedback System, and submit the resulting Feedback System URL to the Grade Book 2.5 assignment in Canvas