2.4 Grade Book Assignment

Grade Book 2.4 — Lists and Average Accuracy

Extend your completed Grade Book 2.3 so a course can hold additional assignments and an instructor can have multiple assistants. Use the diagrams to guide the business-class edits. The weekly schedule and the three-attempt history continue to use arrays.

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

Update the window Title in MainWindow.xaml for 2.4 and your last name. In Properties/AssemblyInfo.cs, update both assembly version numbers to 2.4.0.0. Keep .NET Framework 4.8.

Current Grade Book 2.3 structure. Assignment attempts and the tutoring schedule are arrays. Unrelated members are abbreviated. Object-reference fields are shown only on arrows with visibility; List<> identifies lists and brackets show fixed array dimensions. Properties and constructors share the methods compartment.
Starting structure — your completed Grade Book 2.3
  • New
  • Changed
  • Removed
Offer more assignments and tutoring choices
2.Choose lists for collections that can grow

An array has a fixed number of slots. A List<T> stores a sequence of one specified type and grows when you call Add. The T is a type placeholder: replace it inside the angle brackets with Assignment or Instructor to state which kind of object the list can store. A new empty list has Count equal to zero: creating it does not create any Assignment or Instructor objects. List indexes still begin at zero, but use Count as the loop boundary instead of an array's Length.

Collections in this version
Member Collection type Purpose
Course.Assignments List<Assignment> Add assignments without choosing a fixed slot count
Instructor.Assistants List<Instructor> Search multiple assistants in list order
Assignment.Attempts Attempt[3] Keep the three-attempt limit
TutoringSchedule.Sessions Student[3, 5] Keep three periods across five weekdays
Course changes its assignments array to a list. Instructor replaces Assistant with Assistants and adds an assistant search. Assignment adds an average. Object-reference fields are shown only on arrows with visibility; List<> identifies lists and brackets show fixed array dimensions. Properties and constructors share the methods compartment.
Focused list and average changes
  • New
  • Changed
  • Removed
A In Course.cs, add using System.Collections.Generic; and change Assignments to the public List<Assignment> field shown in the diagram

Inside Course, use the complete field declaration public List<Assignment> Assignments = new List<Assignment>();. This gives each Course object its own empty list.

3.GetAssignmentByType — Search the assignment list
A In Course.cs, modify GetAssignmentByType using the activity diagram

Retain the existing null check and first-match behavior. Replace the array boundary with the list boundary; a type that is not found still returns null.

Search Assignments in list order with Count. Return the first non-null assignment with the requested Type, or null.
Search assignments by Type
  • New
  • Changed
  • Removed
4.Store more than one assistant
A In Instructor.cs, add using System.Collections.Generic; and replace the singular Assistant field with the public Assistants list shown in the focused class diagram

Inside Instructor, use public List<Instructor> Assistants = new List<Instructor>();. Keep the existing using System; directive.

5.GetAssistantByKnowledgeLevel — Find the first suitable assistant
A In Instructor.cs, add GetAssistantByKnowledgeLevel using the focused signature and activity diagram

A foreach loop supplies each Instructor reference in list order. The local result begins as null. When an assistant has strictly greater knowledge, save that reference and break out of the loop. Return result after the loop; do not sort the list or choose the greatest knowledge level.

Search assistants in list order. Return the first assistant with strictly greater knowledge, or null. Equality does not qualify.
Find an assistant with greater knowledge
  • New
  • Changed
  • Removed
6.GetTutor — Use the assistant search
A In Course.cs, modify GetTutor using the activity diagram

Keep Teacher as the fallback. Ask that teacher for a suitable assistant only when the teacher reference is not null. An assistant result replaces the fallback only when a match was found.

GetTutor starts with the teacher as its fallback and substitutes the assistant returned by the new search when available.
Choose the assistant or fall back to the teacher
  • New
  • Changed
  • Removed
7.Configure Blackboard's lists
A In MainWindow.xaml.cs, update newBlackboardButton_Click using the diagrams

Use the object diagram to configure and add the assignments and assistants in the order shown. Keep the existing setup values, relationships, and creation feedback.

Blackboard assignments in order: Plan, HTML Exercises, Website 1. Alan has assistants Donald then Sheldon; list entries refer to the configured objects.
Blackboard assignments and assistants
  • New
  • Changed
  • Removed
8.Configure Canvas's lists
A In MainWindow.xaml.cs, update newCanvasButton_Click using the diagrams

Apply the Canvas object diagram while keeping the existing schedule setup, display refresh, and creation feedback.

Canvas assignments in order: Plan, Short Essay, Term Paper. Jeff has assistants Linus then Samuel; list entries refer to the configured objects.
Canvas assignments and assistants
  • New
  • Changed
  • Removed
B Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve compiler errors and applicable StyleCop warnings before running.
2 Confirm the existing public-field suppression attributes remain. This checkpoint adds no buttons or event-handler names.
C Check Your Work
1 In MainWindow.xaml.cs, set a breakpoint on this.DisplayMessage("Blackboard created."); inside newBlackboardButton_Click.
2 Press F5 and click New Blackboard. When Visual Studio pauses, open Debug > Windows > Watch > Watch 1.
3 Add this.Blackboard.CurrentStudent.Course.Assignments.Count to Watch. Confirm 3.
4 Confirm this.Blackboard.CurrentStudent.Course.Assignments[0].Name is "Plan".
5 Confirm this.Blackboard.CurrentStudent.Course.Assignments[1].Type is "Midterm" and this.Blackboard.CurrentStudent.Course.Assignments[2].Type is "Final".
6 Confirm this.Blackboard.PrimaryInstructor.Assistants.Count is 2.
7 Confirm this.Blackboard.PrimaryInstructor.Assistants[0].Name is "Donald".
8 Confirm this.Blackboard.PrimaryInstructor.Assistants[1].Name is "Sheldon".
9 Remove the Blackboard breakpoint and press F5 before clicking another control.
10 Set a breakpoint on the creation-message statement inside newCanvasButton_Click. Click New Canvas.
11 At the breakpoint, confirm this.Canvas.CurrentStudent.Course.Assignments.Count is 3. Expand indexes 0, 1 and 2 and confirm each holds an Assignment object matching the Canvas object diagram.
12 Confirm this.Canvas.PrimaryInstructor.Assistants.Count is 2.
13 Confirm this.Canvas.PrimaryInstructor.Assistants[0].Name is "Linus" and this.Canvas.PrimaryInstructor.Assistants[1].Name is "Samuel".
14 Confirm this.Canvas.Schedule.Sessions.GetLength(0) is 3 and this.Canvas.Schedule.Sessions.GetLength(1) is 5.
15 Remove the Canvas breakpoint and press F5.
D Check Your Work
1 Set a breakpoint on Instructor result = this.Teacher; inside Course.GetTutor.
2 Create a fresh Blackboard by clicking New Blackboard. Click Tutor Arthur.
3 At the breakpoint, this refers to Arthur’s Course. Confirm knowledgeLevel is approximately 65.5.
4 Press F10 over the fallback assignment and teacher check. Press F11 on the call to GetAssistantByKnowledgeLevel.
5 Inside the assistant-search method, confirm this.Name is "Alan". Here this refers to the instructor, not the Course.
6 Use F10 through the first loop iteration. Confirm this.Assistants[0].Name is "Donald" and this.Assistants[0].KnowledgeLevel is approximately 65.3. Donald does not exceed the supplied 65.5.
7 Continue to the second iteration. Confirm this.Assistants[1].Name is "Sheldon" and this.Assistants[1].KnowledgeLevel is approximately 75.3. This comparison succeeds.
8 Before the return, confirm result.Name is "Sheldon". The result is the existing list reference, not a new Instructor.
9 Step out with Shift+F11. In Course.GetTutor, step past the assistant-result assignment and confirm result.Name is "Sheldon".
10 Remove the breakpoint and press F5. Confirm the status reports Tutoring session completed. with Sheldon as the tutor.
11 Set a breakpoint on the closing brace of tutorArthurButton_Click. Recreate Blackboard and click Tutor Arthur once. At the breakpoint, confirm this.Blackboard.CurrentStudent.KnowledgeLevel is approximately 70.5 and this.Blackboard.CurrentStudent.RequiredSessions is 2. Continue and remove this breakpoint.
12 Restore the breakpoint in Course.GetTutor. Create a fresh Canvas and click Tutor Samantha.
13 Confirm knowledgeLevel is approximately 87.8. Step into the assistant search; neither Linus nor Samuel has greater knowledge.
14 At the assistant-search return, confirm result is null. After returning to Course.GetTutor, confirm its fallback result.Name remains "Jeff".
15 Remove the selection breakpoint. Set a breakpoint on the closing brace of tutorSamanthaButton_Click and continue. At that breakpoint, confirm this.Canvas.CurrentStudent.KnowledgeLevel is approximately 92.8 and this.Canvas.CurrentStudent.RequiredSessions is 3. Remove the breakpoint and continue.
E Check Your Work
1 Open Instructor.GetAssistantByKnowledgeLevel and its activity diagram. Follow the next two cases on paper; do not edit the project or invoke the method through Watch.
2 Use an assistant list with Donald at index 0 and Sheldon at index 1. Their KnowledgeLevel values are approximately 65.3 and 75.3.
3 Trace a supplied knowledgeLevel of 65.3. Confirm equality does not pass the strictly-greater comparison, so Donald is skipped and result.Name becomes "Sheldon".
4 Start a separate trace with knowledgeLevel of 60.0. Confirm Donald is the first match, result.Name becomes "Donald" and break prevents examining Sheldon.
See average accuracy across completed attempts
9.GetAverageAccuracy — Average occupied attempt slots
A In Assignment.cs, add GetAverageAccuracy using the focused signature and activity diagram

Add the Accuracy of every non-null attempt and count those attempts. Include unsuccessful attempts. Divide by the completed-attempt count only when it is greater than zero. Keep the full double result; formatting belongs in the display method.

Sum only occupied attempt slots, count completed attempts, and return total divided by count. Return zero when no attempt is stored.
Calculate average accuracy
  • New
  • Changed
  • Removed
B Check Your Work
1 Open Assignment.GetAverageAccuracy and follow its activity diagram as a source trace. Do not add a temporary caller or call the method through Watch.
2 Use this.Attempts.Length of 3 with this.Attempts[0], this.Attempts[1] and this.Attempts[2] all null.
3 Follow the initializers. Confirm local total is 0.0 and local count is 0.
4 Trace all three array entries. Confirm none passes the non-null check, so total and count remain zero.
5 Follow the result initializer and guard. Confirm average is 0.0, division is skipped because count is zero, and the method returns 0.0.
10.GetAttemptHistory — Append the average
A In Assignment.cs, update GetAttemptHistory using the activity diagram

Keep the existing slot display and best-attempt lookup. Within the existing best-not-null condition, retain the best accuracy and append a new line followed by Average accuracy: , the returned average formatted with ToString("0.##") and a percent sign. Empty histories continue to show three available slots without a summary.

Retain the existing three-slot history loop and best-attempt lookup. Append the average only when a best attempt exists.
History display and average summary
  • New
  • Changed
  • Removed
B Check Your Work
1 Select Build > Build Solution. Open View > Error List and resolve compiler errors and applicable StyleCop warnings before running.
2 Confirm the existing history handlers still call DisplayAssignmentHistories. No temporary average-test caller is needed.
C Check Your Work
1 Remove earlier breakpoints. Click New Blackboard, then click Take midterm exactly twice. Do not take another assignment yet.
2 In blackboardHistoryButton_Click, set a breakpoint on its call to DisplayAssignmentHistories. Click Show Blackboard attempt history.
3 At this breakpoint, this refers to MainWindow. Confirm this.Blackboard.CurrentStudent.Course.Assignments[1].Attempts.Length is 3.
4 Confirm this.Blackboard.CurrentStudent.Course.Assignments[1].Attempts[0].Accuracy is approximately 79.575 and this.Blackboard.CurrentStudent.Course.Assignments[1].Attempts[1].Accuracy is approximately 82.075.
5 Confirm this.Blackboard.CurrentStudent.Course.Assignments[1].Attempts[2] is null.
6 Set a second breakpoint on double total = 0; inside Assignment.GetAverageAccuracy. Press F5.
7 When that breakpoint is reached, confirm this.Name is "HTML Exercises". Now this refers to that Assignment.
8 Open Watch and add total, count, average, this.Attempts.Length and this.Attempts[2].
9 Press F10 over the total and count initializers. Confirm total is 0.0 and count is 0.
10 Step through the first occupied attempt. Confirm total is approximately 79.575 and count is 1.
11 Step through the second occupied attempt. Confirm total is approximately 161.65 and count is 2.
12 Step through the null third slot. Confirm neither total nor count changes.
13 Step past the average initializer and guarded division. Confirm average is approximately 80.825.
14 Remove both breakpoints and press F5. Confirm the HTML Exercises history shows two attempts, best accuracy 82.08%, and average accuracy 80.83%.
15 Confirm Plan and Final still show three available slots each and no average summary.
D Check Your Work
1 Continue from the preceding two-midterm state. Set a breakpoint on the closing brace of the Blackboard midterm event handler. Click Take midterm a third time; at the pause, record this.Blackboard.CurrentStudent.KnowledgeLevel. Press F5 to continue.
2 Click Show Blackboard attempt history. Confirm HTML Exercises now has three attempts, best accuracy 84.58% and average accuracy 82.08%.
3 Remove the closing-brace breakpoint and set one on the first executable statement of the same handler. Click Take midterm a fourth time. Use F10 through the blocked attempt; before the handler returns, compare this.Blackboard.CurrentStudent.KnowledgeLevel with your recorded value and confirm it has not increased. Continue and confirm the message reports that all three attempts have been used.
4 Show the history again. Confirm no fourth attempt appears and the best and average values stay unchanged.
5 Remove the midterm-handler breakpoint and press F5 before starting the next independent check.
E Check Your Work
1 Click New Blackboard to restore the starting student and assignment state.
2 Click Take final once, then Show Blackboard attempt history.
3 Confirm Website 1 has one stored attempt with grade F and accuracy 66.55%.
4 Confirm its best accuracy and average accuracy are both 66.55%.
5 Compare the average method’s condition with the submission rule. Confirm the average includes every non-null Attempt, even when that attempt is not retained as the passing Submission.
11.Check the existing tutoring and schedule behavior
A Check Your Work
1 Click New Canvas. Reserve Monday, period 1, for Samantha using the existing schedule controls.
2 Set a breakpoint on the closing brace of attendButton_Click. Click Attend.
3 At the breakpoint, confirm this.Canvas.Schedule.Sessions[0, 0] is null.
4 Confirm this.Canvas.CurrentStudent.KnowledgeLevel is approximately 92.8 and this.Canvas.CurrentStudent.RequiredSessions is 3.
5 Remove the breakpoint and press F5. Confirm the Monday-period-1 cell changes from [X] to [ ] and the displayed reservation count returns to 0.
6 Confirm the status includes Jeff’s knowledge and Samantha’s current tutoring details.
B Check Your Work
1 Click New Canvas. Reserve Monday, period 1, for Samantha.
2 Click Complete Samantha tutoring. Confirm two sessions complete, Samantha’s KnowledgeLevel reaches approximately 95.0 and RequiredSessions remains 2.
3 Confirm the Monday-period-1 reservation is still [X]. Direct tutoring does not consume it.
4 Set a breakpoint on the closing brace of attendButton_Click. Click Attend. Confirm the message begins No tutor has a higher knowledge level. Reservation retained..
5 Pause at the closing brace of attendButton_Click. Confirm this.Canvas.Schedule.Sessions[0, 0] still refers to this.Canvas.CurrentStudent.
6 Confirm this.Canvas.CurrentStudent.KnowledgeLevel is still approximately 95.0 and this.Canvas.CurrentStudent.RequiredSessions is still 2.
7 Remove the breakpoint and continue. Confirm the reservation count is unchanged, then cancel this reservation to clear the cell.
C Check Your Work
1 Stop debugging. In newCanvasButton_Click, find the starting assignment to this.Canvas.CurrentStudent.RequiredSessions. Temporarily change only its value from 4 to 1.
2 Build and start the application. Click New Canvas and reserve Monday, period 1, for Samantha.
3 Click Tutor Samantha once. Confirm one session completes, this.Canvas.CurrentStudent.RequiredSessions becomes 0 and the reservation stays [X].
4 Set a breakpoint on the closing brace of attendButton_Click. Click Attend. Confirm the message begins No tutoring sessions are required. Reservation retained..
5 At the closing brace of attendButton_Click, confirm this.Canvas.Schedule.Sessions[0, 0] still refers to Samantha, this.Canvas.CurrentStudent.RequiredSessions remains 0 and her KnowledgeLevel has not increased again.
6 Stop debugging. Restore the starting RequiredSessions assignment to 4, remove the test breakpoint, rebuild, and create a fresh Canvas before continuing.
D Check Your Work
1 Stop and restart the application. Do not click either New button.
2 Click Tutor Arthur. Confirm Create Blackboard first. appears without an exception.
3 Click Attend. Confirm Create Canvas first. appears without an exception.
12.Review the completed structure
Grade Book 2.4 ending structure. Blue marks changed members and green marks new members. Attempts and Sessions remain arrays. Object-reference fields are shown only on arrows with visibility; List<> identifies lists and brackets show fixed array dimensions. Properties and constructors share the methods compartment.
Ending structure — lists and average accuracy
  • New
  • Changed
  • Removed
A Explain why assignments and assistants use lists while attempts and the weekly schedule remain arrays
B Check Your Work
1 Confirm Samantha’s starting RequiredSessions value in newCanvasButton_Click is restored to 4.
2 Remove all test breakpoints and save every modified file.
3 Select Build > Build Solution. Open View > Error List and resolve compiler errors and applicable StyleCop warnings before running.
4 Recreate Blackboard and Canvas. Confirm their list counts and order still match the object diagrams, and repeat the successful tutoring and average checks above.