- 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.
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.
Keep the assignment attempts, history, and existing tutoring features from your previous version.
DisplayAssignmentHistories in MainWindow.xaml.csMainWindow.xaml.cs, update only the loop in DisplayAssignmentHistories. Use the activity diagram to replace its indexed for loop with foreach.Blackboard, take a midterm, and show its history. Confirm the same attempt information appears as in 2.2.TutoringSchedule.cs to Business ClassesSessions field.Schedule field to GradeBook.cs using the focused changes diagram.Student references in a rectangular two-dimensional array.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.
| 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] |
| Expression | Result | Meaning |
|---|---|---|
Sessions.GetLength(0) |
3 | Number of period rows |
Sessions.GetLength(1) |
5 | Number of weekday columns |
Sessions.Length |
15 | Total cells |
Sessions[0, 0].Sessions[2, 4].IsValidLocation to TutoringSchedule.csGetStudent to TutoringSchedule.csStudent reference or null.null.Book to TutoringSchedule.csStudent reference only when the request succeeds.Book activity diagram, trace an empty valid cell with RequiredSessions equal to 0. Confirm the returned result is 5.| 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 |
TutoringSchedule.csfalse.null and the result is true.TutoringSchedule.csGetHelp method.GetHelp reports a completed session.RequiredSessions and a failed GetHelp call: the no-higher-knowledge message is returned and the reservation is retained.RequiredSessions equal to 0: return the no-sessions-required message before calling GetHelp, retaining the reservation.RequiredSessions decreases through GetHelp and the attended cell becomes null.CountBookings to TutoringSchedule.csStudent reference with foreach.GetDisplay to TutoringSchedule.csMainWindow.xaml, insert this complete block after the End Canvas buttons comment, inside the Canvas StackPanel and before StackPanel.Resources<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>
statusTextBox.Height to 220These 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.
Blackboard and Canvas buttons remain present. Full build verification follows after the named handlers are added.MainWindow constructor, keep InitializeComponent and add the selection setup after it using the activity diagramSelectedIndex values start at 0.DisplaySchedule to MainWindow.xaml.csscheduleDisplayTextBox.CountBookings with Canvas.CurrentStudent; the count is not a separate maintained field.newCanvasButton_Click after its existing assistant salary assignmentDisplaySchedule, then DisplayMessage("Canvas created.") so the new map and creation feedback appear without an extra button.Canvas.CurrentStudent exists and Sessions has been allocated before DisplaySchedule runs.MainWindow.xaml.cs, add GetTutoringDetails using the focused class and activity diagramsStudent student and Instructor tutor parameters and return a string.RequiredSessions values.MainWindow.xaml.cs, replace tutorArthurButton_Click with this complete exampleprivate 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));
}tutorSamanthaButton_Click using the differences table and its activity diagram| 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 |
RequiredSessions equal to 0: no GetHelp call occurs and the message is No tutoring sessions are required.RequiredSessions with GetHelp returning false: the message is No tutor has a higher knowledge level.MainWindow.xaml.cs, update completeTutoringButton_Click using its activity diagramCompleteRequiredTutoring runs.GetTutoringDetails for Canvas.CurrentStudent and the captured tutor, then display the message.RequiredSessions equal to 0 selects No tutoring sessions are required.; a positive value selects No tutor has a higher knowledge level.MainWindow.xaml.cs, finish newBlackboardButton_Click with DisplayMessage("Blackboard created.") after the existing initialization statementsDisplayMessage itself still only assigns statusTextBox.Text.MainWindow.xaml.cs, add the complete Book handler belowprivate 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);
}| 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 |
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.
name matches an existing handler exactly, then build the solution.Book Monday period 1 again. Confirm the occupied-cell message and an unchanged count.Book Tuesday period 2. Confirm both reservations remain visible and the count becomes 2.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.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.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.Tutor Samantha. Confirm Jeff is shown at 95, Samantha at 92.8 with 3 required sessions, and all three reservations remain.Tutor Samantha. Confirm her knowledge is 97.8, Jeff's is 95, no session completes, and the message gives the insufficient-knowledge reason.Canvas.Schedule.Book call in bookButton_ClickBook selected student to pause on the call.Book| 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 |
Book and observe student.Name, day, period, and this.Sessions become available in the schedule’s context.IsValidLocation when it is called. Add this.Sessions.GetLength(0) and this.Sessions.GetLength(1) to Watch; confirm 3 and 5.Book and confirm it continues past the location check.Sessions[period, day]. Expand the array in Watch and confirm [0,0] now refers to Samantha.bookButton_Click. Once the assignment completes, confirm result contains 0. The handler’s locals are now in scope again.DisplayScheduleGetDisplay call and inspect display in Watch. The returned text contains one booked cell.CountBookings is called, use F11 to enter it. If the debugger enters a framework getter first, continue stepping until the schedule method is reached.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.DisplaySchedule. Step past the text assignment and confirm the schedule box shows the map and Samantha reservations: 1.this.Canvas stopped being available inside the schedule and why this.Sessions became available there.CountBookings can use foreach without row or column indexes.Canvas.CurrentStudent can refer to the same Student, and why clearing a reservation does not delete that student