2.3 Grade Book Assignment

Grade Book 2.3 — Tutoring Reservations

Extend your completed Grade Book 2.2 with a weekly Canvas tutoring schedule. Each schedule cell stores a Student reference. Use the diagrams to build the methods and the checks to confirm their behavior.

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

Keep the assignment attempts, history, and existing tutoring features from your previous version.

Current Grade Book 2.2 structure, without change markers. Unrelated members and event methods are abbreviated below compartment separators.
Starting structure — your completed Grade Book 2.2
  • New
  • Changed
  • Removed
2.DisplayAssignmentHistories — Read the existing array with foreach
A Update DisplayAssignmentHistories in MainWindow.xaml.cs
1 In MainWindow.xaml.cs, update only the loop in DisplayAssignmentHistories. Use the activity diagram to replace its indexed for loop with foreach.
2 Use the current Assignment reference inside the loop, keeping the existing null check, history text, and blank lines.
Control flow for DisplayAssignmentHistories from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
DisplayAssignmentHistories activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Create Blackboard, take a midterm, and show its history. Confirm the same attempt information appears as in 2.2.
Reserve a Weekday and Period
Acceptance Criteria
  • The schedule has three periods for each weekday from Monday through Friday.
  • A reserved cell shows [X]; an available cell shows [ ].
  • A student can reserve at most one period on the same day.
3.Create the tutoring schedule
A Add TutoringSchedule.cs to Business Classes
1 Use the focused class diagram to add the Sessions field.
2 Add the Schedule field to GradeBook.cs using the focused changes diagram.
Focused changes: GradeBook gains Schedule, MainWindow gains DisplaySchedule, and DisplayAssignmentHistories changes traversal.
The members added or changed in this lesson
  • New
  • Changed
  • Removed
New schedule field and all seven new method signatures. Green markers identify new members.
TutoringSchedule fields and method signatures
  • New
  • Changed
  • Removed
B Check Your Work
1 Compare the field types with the diagrams: the schedule stores Student references in a rectangular two-dimensional array.
4.Read the schedule as rows and columns

The schedule will use new Student[3, 5]. Rows represent periods and columns represent weekdays. This table shows array indexes, not the period numbers printed for students.

Schedule indexes
Monday (0) Tuesday (1) Wednesday (2) Thursday (3) Friday (4)
0 [0, 0] [0, 1] [0, 2] [0, 3] [0, 4]
1 [1, 0] [1, 1] [1, 2] [1, 3] [1, 4]
2 [2, 0] [2, 1] [2, 2] [2, 3] [2, 4]
Lengths and indexes
Expression Result Meaning
Sessions.GetLength(0) 3 Number of period rows
Sessions.GetLength(1) 5 Number of weekday columns
Sessions.Length 15 Total cells
A Predict which cell each selection refers to
1 Monday, period 1 refers to Sessions[0, 0].
2 Friday, period 3 refers to Sessions[2, 4].
5.IsValidLocation — Return the result of a combined condition
A Add IsValidLocation to TutoringSchedule.cs
1 Use the class diagram to determine the return type and parameters.
2 Use the activity diagram to return whether both indexes are inside their corresponding dimensions.
Control flow for IsValidLocation from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
IsValidLocation activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace the return for day 0 and period 0; it should be true.
2 Trace day 4 and period 2, then day 5 and period 2. Only the first pair should be valid.
3 Trace day 0 with periods -1 and 3. Both should be invalid.
C Explore why the single return works
1 Identify the four conditions in the activity diagram and explain what each one prevents.
2 On paper, express the same test as an if/else returning true or false. Compare its results with the single return; keep the single-return form in your project.
6.GetStudent — Read the selected cell safely
A Add GetStudent to TutoringSchedule.cs
1 Use the class diagram for the method signature.
2 Follow the activity diagram to check the location before reading the cell and return either its Student reference or null.
Control flow for GetStudent from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
GetStudent activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace an empty valid cell: the return is null.
2 Trace an invalid location: no array access should occur.
7.Book — Store a reservation
A Add Book to TutoringSchedule.cs
1 Use the class diagram for the method signature and the result table below for the return values.
2 Use the first activity diagram for the request checks. Preserve their order because the first failure determines the result.
3 Continue with the second activity diagram to search that weekday’s column and store the existing Student reference only when the request succeeds.
Control flow for BookRequestChecks from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
BookRequestChecks activity
  • New
  • Changed
  • Removed
Control flow for BookDaySearch from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
BookDaySearch activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace an already occupied cell: the method returns 3 before any new reference is stored.
2 Trace an empty cell on a day where the same student is already booked: the method returns 4.
3 Trace a successful request: the selected cell refers to the supplied student.
4 On the first Book activity diagram, trace an empty valid cell with RequiredSessions equal to 0. Confirm the returned result is 5.
Book return values
Result Meaning
0 Reservation stored
1 Missing student
2 Invalid day or period
3 Selected cell is occupied
4 Student is already booked that day
5 Student requires no tutoring
Inspect, Cancel, or Attend a Reservation
Acceptance Criteria
  • Inspection identifies the student reserved in the selected cell.
  • Cancellation frees the selected cell.
  • Successful attendance tutors the reserved student and frees that cell.
  • If tutoring cannot proceed, the reservation remains in place.
8.Cancel — Empty one occupied cell
A Add Cancel to TutoringSchedule.cs
1 Use the class diagram for the method signature.
2 Follow the activity diagram to validate the location and read its student before deciding whether to clear that cell.
Control flow for Cancel from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
Cancel activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace cancellation of an empty cell: the result is false.
2 Trace cancellation of an occupied cell: only that cell becomes null and the result is true.
9.Attend — Tutor the reserved student
A Add Attend to TutoringSchedule.cs
1 Use the class diagram for the method signature.
2 Follow the activity diagram to read the reserved student and use the existing GetHelp method.
3 Use the diagram’s separate messages for no required sessions and no tutor with higher knowledge. Clear the cell only when GetHelp reports a completed session.
Attend separates no required sessions from insufficient tutor knowledge and retains failed reservations.
Attend activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace an empty cell: the method returns the no-reservation message.
2 Trace a student with positive RequiredSessions and a failed GetHelp call: the no-higher-knowledge message is returned and the reservation is retained.
3 Trace an occupied cell whose student has RequiredSessions equal to 0: return the no-sessions-required message before calling GetHelp, retaining the reservation.
4 Trace successful attendance: RequiredSessions decreases through GetHelp and the attended cell becomes null.
Canvas.CurrentStudent and two occupied cells of the three-by-five schedule refer to the same Samantha object.
Several reservations can refer to the same student
  • New
  • Changed
  • Removed
See the Schedule and My Reservation Count
Acceptance Criteria
  • Creating Canvas displays an empty weekly schedule.
  • The reservation count appears on a separate line.
  • Booking, cancellation, and attendance refresh the schedule and count.
10.CountBookings — Count references to one student
A Add CountBookings to TutoringSchedule.cs
1 Use the class diagram for the method signature.
2 Follow the activity diagram to check every stored Student reference with foreach.
3 Use the diagram’s condition to increase the count only for a reference to the requested student, then return the final count.
Control flow for CountBookings from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
CountBookings activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace a null student argument: empty cells must not be counted as that student.
2 Trace two cells referring to Samantha and the other cells null: the returned count is 2.
11.GetDisplay — Build the weekly map
A Add GetDisplay to TutoringSchedule.cs
1 Use the class diagram for the method signature.
2 Use the activity diagram to build the weekday header and one display line for each period. Read the outer and inner loop conditions carefully.
3 Follow the decisions to add an empty or booked marker and the line breaks. Return the completed string.
Control flow for GetDisplay from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
GetDisplay activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace the nested loops for one period: five cells contribute markers before the next row begins.
2 Confirm the displayed period numbers start at 1 while their array indexes start at 0.
12.Add the Canvas schedule controls
A In MainWindow.xaml, insert this complete block after the End Canvas buttons comment, inside the Canvas StackPanel and before StackPanel.Resources
Canvas tutoring schedule controls
<GroupBox Header="Canvas tutoring schedule" Margin="0,8,0,0">
    <StackPanel Margin="5">
        <TextBlock Text="X means booked. Inspect a cell to see its student." Margin="3" TextWrapping="Wrap"/>

        <TextBox x:Name="scheduleDisplayTextBox" Height="105" FontFamily="Consolas" FontSize="12"
                 IsReadOnly="True" AcceptsReturn="True" HorizontalScrollBarVisibility="Auto"/>

        <WrapPanel>
            <TextBlock Text="Day:" VerticalAlignment="Center"/>
            <ComboBox x:Name="dayComboBox" Width="125"/>
            <TextBlock Text="Period:" VerticalAlignment="Center" Margin="8,0,0,0"/>
            <ComboBox x:Name="periodComboBox" Width="65"/>
        </WrapPanel>

        <WrapPanel>
            <Button x:Name="bookButton" Content="Book selected student" Click="bookButton_Click"/>
            <Button x:Name="inspectBookingButton" Content="Inspect" Click="inspectBookingButton_Click"/>
            <Button x:Name="cancelBookingButton" Content="Cancel reservation" Click="cancelBookingButton_Click"/>
            <Button x:Name="attendButton" Content="Attend" Click="attendButton_Click"/>
        </WrapPanel>

        <TextBlock Text="Attendance tutors the reserved student and clears that cell. Direct tutoring leaves reservations in place."
                   Margin="3" TextWrapping="Wrap"/>
    </StackPanel>
</GroupBox>
B Update the Window title to Programming Concepts 2: Grade Book 2.3 End, set its Height to 820, and set statusTextBox.Height to 220

These dimensions leave room for the schedule controls and the existing status area. Keep every new control name, button Content, and Click handler name exactly as shown.

C Check Your Work
1 Confirm the schedule is on the Canvas side and the existing Blackboard and Canvas buttons remain present. Full build verification follows after the named handlers are added.
13.Initialize the day and period choices
A In the existing MainWindow constructor, keep InitializeComponent and add the selection setup after it using the activity diagram
Control flow for InitializeScheduleSelections from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
Initialize the existing window’s new selection controls
  • New
  • Changed
  • Removed
B Check Your Work
1 Compare the initialization with the diagram: both SelectedIndex values start at 0.
14.DisplaySchedule — Refresh the map and count
A Add DisplaySchedule to MainWindow.xaml.cs
1 Use the focused class diagram for the method signature.
2 Follow the activity diagram to handle a missing Canvas and obtain the schedule display.
3 Add the student’s reservation count on a separate line, then assign the completed text to scheduleDisplayTextBox.
Control flow for DisplaySchedule from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
DisplaySchedule activity
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace a null Canvas reference: the method returns before accessing its schedule.
2 Confirm the method calls CountBookings with Canvas.CurrentStudent; the count is not a separate maintained field.
15.Create the schedule with Canvas
A Update newCanvasButton_Click after its existing assistant salary assignment
1 Use the activity diagram to create the schedule and its array after the existing Canvas objects are initialized.
2 Call DisplaySchedule, then DisplayMessage("Canvas created.") so the new map and creation feedback appear without an extra button.
Control flow for InitializeCanvasSchedule from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
Create and display the Canvas schedule
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace the added setup: Canvas.CurrentStudent exists and Sessions has been allocated before DisplaySchedule runs.
Understand Each Tutoring Result
Acceptance Criteria
  • Each tutoring action shows only its relevant student and selected tutor.
  • The lower message area shows the tutor's name and knowledge, the student's current knowledge, and remaining required sessions.
  • No sessions required and no tutor with higher knowledge produce different messages.
16.GetTutoringDetails — Format the relevant levels
A In MainWindow.xaml.cs, add GetTutoringDetails using the focused class and activity diagrams
1 Use Student student and Instructor tutor parameters and return a string.
2 Follow the activity diagram to describe the supplied tutor, then append the student's current knowledge and remaining sessions.
GetTutoringDetails formats the captured tutor and current student knowledge and required sessions without mutating either object.
Build feedback for one student and the tutor selected for the action
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace a null tutor: the output begins with No tutor is available. and still includes the student's current values.
2 Trace Samantha with Jeff: the tutor line identifies Jeff and 95, followed by Samantha's knowledge and RequiredSessions values.
17.Explain the result of manual tutoring
A In MainWindow.xaml.cs, replace tutorArthurButton_Click with this complete example
Manual tutoring with separate outcomes
private void tutorArthurButton_Click(object sender, RoutedEventArgs e)
{
    if (this.Blackboard == null)
    {
        this.DisplayMessage("Create Blackboard first.");

        return;
    }

    Student student = this.Blackboard.CurrentStudent;
    Instructor tutor = student.Course.GetTutor(student.KnowledgeLevel);
    string message;

    if (student.RequiredSessions == 0)
    {
        message = "No tutoring sessions are required.";
    }
    else if (student.GetHelp())
    {
        message = "Tutoring session completed.";
    }
    else
    {
        message = "No tutor has a higher knowledge level.";
    }

    this.DisplayMessage(message + System.Environment.NewLine + this.GetTutoringDetails(student, tutor));
}
B Update tutorSamanthaButton_Click using the differences table and its activity diagram
Manual tutoring handlers
Handler Missing-gradebook guard Student reference
tutorArthurButton_Click Blackboard == null; DisplayMessage("Create Blackboard first."); return Blackboard.CurrentStudent
tutorSamanthaButton_Click Canvas == null; DisplayMessage("Create Canvas first."); return Canvas.CurrentStudent
Manual tutoring for Arthur captures the tutor before GetHelp and reports separate completion, no-session, and insufficient-knowledge outcomes.
Arthur's manual tutoring action
  • New
  • Changed
  • Removed
Manual tutoring for Samantha captures the tutor before GetHelp and reports separate completion, no-session, and insufficient-knowledge outcomes.
Samantha's manual tutoring action
  • New
  • Changed
  • Removed
C Check Your Work
1 Trace RequiredSessions equal to 0: no GetHelp call occurs and the message is No tutoring sessions are required.
2 Trace positive RequiredSessions with GetHelp returning false: the message is No tutor has a higher knowledge level.
18.Explain why automatic tutoring stops
A In MainWindow.xaml.cs, update completeTutoringButton_Click using its activity diagram
1 After the existing Canvas guard, capture the selected tutor before CompleteRequiredTutoring runs.
2 Follow the diagram to build the completed-session count and select the stopping message from the remaining requirement.
3 Append GetTutoringDetails for Canvas.CurrentStudent and the captured tutor, then display the message.
Complete Samantha tutoring reports the completed count and distinguishes a completed requirement from insufficient tutor knowledge.
Report completed sessions and the reason processing stopped
  • New
  • Changed
  • Removed
B Check Your Work
1 Trace the final condition twice: RequiredSessions equal to 0 selects No tutoring sessions are required.; a positive value selects No tutor has a higher knowledge level.
19.Report creation in the message area
A In MainWindow.xaml.cs, finish newBlackboardButton_Click with DisplayMessage("Blackboard created.") after the existing initialization statements
B Check Your Work
1 Confirm both creation handlers now supply their own short message; DisplayMessage itself still only assigns statusTextBox.Text.
20.Connect the reservation buttons
A In MainWindow.xaml.cs, add the complete Book handler below
First reservation event handler
private void bookButton_Click(object sender, RoutedEventArgs e)
{
    if (this.Canvas == null)
    {
        this.DisplayMessage("Create Canvas first.");
        return;
    }

    int day = this.dayComboBox.SelectedIndex;
    int period = this.periodComboBox.SelectedIndex;
    int result = this.Canvas.Schedule.Book(this.Canvas.CurrentStudent, day, period);
    string message;

    switch (result)
    {
        case 0:
            message = "Tutoring reserved for " + this.Canvas.CurrentStudent.Name + ".";
            break;
        case 1:
            message = "No student is available to book.";
            break;
        case 2:
            message = "Select a weekday and period 1 through 3.";
            break;
        case 3:
            message = "That tutoring period is already reserved.";
            break;
        case 4:
            message = "The student already has a reservation that day.";
            break;
        case 5:
            message = "The student does not require tutoring.";
            break;
        default:
            message = "The reservation could not be completed.";
            break;
    }

    this.DisplaySchedule();
    this.DisplayMessage(message);
}
Control flow for BookButton from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
Book handler coordination
  • New
  • Changed
  • Removed
B Use the same create-Canvas guard for the other three handlers; use the table and their activity diagrams for their distinct behavior
Remaining reservation handlers
Handler Schedule method Arguments Finish with
inspectBookingButton_Click GetStudent, after IsValidLocation day and period from the two SelectedIndex values DisplayMessage
cancelBookingButton_Click Cancel dayComboBox.SelectedIndex, periodComboBox.SelectedIndex DisplaySchedule, then DisplayMessage
attendButton_Click GetStudent before Attend; GetTutoringDetails for an occupied cell dayComboBox.SelectedIndex, periodComboBox.SelectedIndex DisplaySchedule, then DisplayMessage
Control flow for InspectBookingButton from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
InspectBookingButton activity
  • New
  • Changed
  • Removed
Control flow for CancelBookingButton from the current Grade Book 2.3 source. Yes and no paths are labeled; returns end the method.
CancelBookingButton activity
  • New
  • Changed
  • Removed
Attendance captures the reserved student and selected tutor before the session, then appends their relevant current levels and refreshes the schedule.
AttendButton activity
  • New
  • Changed
  • Removed

Each handler uses the standard sender and RoutedEventArgs e parameters and returns void. Follow its diagram for the exact message selection; the three bodies are not identical.

C Check Your Work
1 Confirm each new XAML Click name matches an existing handler exactly, then build the solution.
The booking click stores Samantha through the schedule and then refreshes the map and reservation count.
From Book click to stored reference and refreshed count
  • New
  • Changed
  • Removed
Attendance calls existing student tutoring, clears only a completed reservation, and refreshes the schedule.
From Attend click to tutoring and refreshed schedule
  • New
  • Changed
  • Removed
21.Test the completed schedule
A Check Your Work
1 Before creating Canvas, click each schedule action. Each reports Create Canvas first. without an exception.
2 Create Canvas. Confirm three empty period rows, five weekdays, and Samantha reservations: 0 on its own line.
3 Select Monday and period 1, then book. Confirm [X] in that cell and Samantha reservations: 1.
4 Book Monday period 1 again. Confirm the occupied-cell message and an unchanged count.
5 Select Monday period 2 and book. Confirm the already-booked-that-day message and an unchanged count.
6 Book Tuesday period 2. Confirm both reservations remain visible and the count becomes 2.
7 Inspect Tuesday period 2. Confirm Samantha is identified with her current remaining tutoring requirement.
8 Cancel Tuesday period 2. Confirm only that cell becomes empty and the count returns to 1.
9 Attend Monday period 1. Confirm the cell becomes empty, the reservation count becomes 0, and Samantha now requires 3 sessions.
10 Recreate Canvas, book Monday period 1, and click Complete Samantha tutoring. Then attend that booking: tutoring cannot continue once Jeff has no higher knowledge, and the reservation is retained. Cancel it and confirm the cell becomes empty.
11 Recreate Blackboard and click Tutor Arthur three times. The first two sessions identify Sheldon, with Arthur reaching 70.5 and then 75.3. The third identifies Alan and Arthur reaches 80.3 with no sessions remaining.
12 Click Tutor Arthur once more. Confirm No tutoring sessions are required., Arthur remains at 80.3, and no session is performed. Only Arthur and his selected tutor appear in the message.
13 Recreate Canvas and book period 1 on Monday, Tuesday, and Wednesday. Click Tutor Samantha. Confirm Jeff is shown at 95, Samantha at 92.8 with 3 required sessions, and all three reservations remain.
14 Attend Wednesday period 1. Confirm Samantha reaches 95 with 2 required sessions and only that reservation is cleared. Attend Monday period 1: confirm No tutor has a higher knowledge level., both remaining reservations stay booked, and the feedback still shows Jeff at 95 and Samantha at 95.
15 Recreate Canvas, write a midterm essay, then write the final paper. Click Tutor Samantha. Confirm her knowledge is 97.8, Jeff's is 95, no session completes, and the message gives the insufficient-knowledge reason.
16 Take assignments and show both histories. Confirm earlier attempt limits, grades, and tutoring actions still work.
22.Follow a booking through methods and Watch
A Set a breakpoint on the Canvas.Schedule.Book call in bookButton_Click
1 Start debugging, create Canvas, select Monday and period 1, then click Book selected student to pause on the call.
B Open Watch 1 and add these expressions before stepping into Book
Watch at the booking call
Expression Before stepping into Book After entering Book
this.Canvas.Schedule.Sessions Empty Student[3,5] array Unavailable when this refers to TutoringSchedule
day 0, the handler’s local 0, the Book parameter
period 0, the handler’s local 0, the Book parameter
student.Name Unavailable in the handler "Samantha"
this.Sessions Unavailable in MainWindow The schedule array
this.Sessions[period, day] Unavailable in MainWindow null before the booking is stored
result Not yet assigned by the Book call Unavailable inside Book
C Use Step Into (F11) to follow the call
1 Press F11 into Book and observe student.Name, day, period, and this.Sessions become available in the schedule’s context.
2 Use F11 to enter IsValidLocation when it is called. Add this.Sessions.GetLength(0) and this.Sessions.GetLength(1) to Watch; confirm 3 and 5.
3 Inspect the four conditions for the selected indexes, then follow the return to Book and confirm it continues past the location check.
4 Step through the day-column search. Add row to Watch when its declaration runs and observe it change while day remains 0.
5 Execute the assignment to Sessions[period, day]. Expand the array in Watch and confirm [0,0] now refers to Samantha.
6 Follow return 0 back to bookButton_Click. Once the assignment completes, confirm result contains 0. The handler’s locals are now in scope again.
D Step through the switch, then use F11 to enter DisplaySchedule
1 Step Over (F10) the GetDisplay call and inspect display in Watch. The returned text contains one booked cell.
2 When CountBookings is called, use F11 to enter it. If the debugger enters a framework getter first, continue stepping until the schedule method is reached.
3 Add count, student.Name, and bookedStudent to Watch. Step through the foreach loop: count increases only when the stored reference is Samantha; null cells do not contribute.
4 Return to DisplaySchedule. Step past the text assignment and confirm the schedule box shows the map and Samantha reservations: 1.
E Check Your Work
1 Explain why this.Canvas stopped being available inside the schedule and why this.Sessions became available there.
2 Explain why the coordinate search uses for while CountBookings can use foreach without row or column indexes.
3 Remove the breakpoint and continue (F5). Recreate Canvas to reset the scenario.
23.Review the completed structure
Ending structure with new schedule members in green and changed history traversal in blue. The constructor and Canvas creation event also gain setup described in their tasks.
Ending structure — new and changed members
  • New
  • Changed
  • Removed
A Explain how a schedule cell and Canvas.CurrentStudent can refer to the same Student, and why clearing a reservation does not delete that student
24.Submit Grade Book 2.3
A Save and submit the completed Grade Book 2.3 project using your course’s submission procedure