- Each course stores its midterm and final in a two-element assignment array.
- The existing exam buttons still select the correct assignment.
- Searching skips empty elements and returns
nullwhen no assignment matches.
Build and run before editing. Your existing assignment feedback and tutoring actions should work. Keep the original student, instructor, course, and assignment values as you move assignment references into arrays.
null when no assignment matches.Course.cs, replace the Midterm and Final fields with AssignmentsUse the focused class diagram for the field type. Initialize the field with a new two-element array. A newly created array contains two null references; creating the array does not create its Assignment objects.
MainWindow.xaml.cs, initialize the two array elementsIn newBlackboardButton_Click and newCanvasButton_Click, replace each former Midterm reference with Assignments[0] and each former Final reference with Assignments[1]. Create an Assignment at each element before setting its fields. Retain these exact values and all other initialization statements.
| Grade book | Index | Name | Difficulty | Points | Type |
|---|---|---|---|---|---|
| Blackboard | 0 | HTML Exercises | 12.7 | 100.0 | Midterm |
| Blackboard | 1 | Website 1 | 64.8 | 100.0 | Final |
| Canvas | 0 | Short Essay | 31.3 | 100.0 | Midterm |
| Canvas | 1 | Term Paper | 66.2 | 100.0 | Final |
Course.cs, revise GetAssignmentByType(string type)Replace the old two-field decision with the activity diagram's search. Use a for loop, return the first matching Assignment reference, and preserve null as the result when no element matches.
GetAssignmentByTypeTrigger each exam button once. In Locals, Blackboard should select HTML Exercises or Website 1; Canvas should select Short Essay or Term Paper. Recreate each grade book before its independent trial so learning does not alter your starting values.
nullA Quiz search should inspect all available elements and return null. With element zero null, searching for Final should still find element one. Explain which condition prevents access to Type on a null element. These are source traces; the normal buttons do not request Quiz or empty an assignment element.
Assignment.cs, add and initialize Attempts using the focused class diagramCreate a three-element array in the field initializer. Keep Submission as a separate Attempt reference. Each new Assignment gets its own array.
Assignment.cs, add FindAvailableAttempt()Use the signature diagram and this activity diagram. Search for the first null element, return its zero-based index, and return -1 when the array is full.
Trace the activity diagram for each array below. You will observe the same searches through the buttons after connecting submission.
Attempts[0] |
Attempts[1] |
Attempts[2] |
Returned index |
|---|---|---|---|
| null | null | null | 0 |
| an attempt | null | null | 1 |
| an attempt | an attempt | null | 2 |
| an attempt | an attempt | an attempt | -1 |
| null | an attempt | null | 0 |
Assignment.cs, change Submit to accept the attempt and its instructorUse the exact signature in the focused class diagram. The instructor parameter supplies the object that grades the attempt. Within Assignment, pass this as the assignment argument to Grade.
Let this method find the available slot, guard missing arguments or a full history, ask the instructor to grade, retain the attempt, and decide whether Submission should change.
Trace Submit for these independent cases. Assume an available slot and a valid instructor unless the row says otherwise.
| Condition | History result | Submission result |
|---|---|---|
| First attempt has accuracy 66.55 | Attempt is retained |
Remains null |
| First attempt has accuracy 79.575 | Attempt is retained |
Refers to this passing attempt |
| Existing submission is 85 and new attempt is 80 | New attempt is retained | Keeps the existing 85 result |
| Existing submission is 85 and new attempt is 85 | New attempt is retained | Keeps the earlier reference |
| History is full | No element changes | No change |
Submission argument or instructor is null |
No element changes | No change |
Student.cs, revise TakeAssignment(string type, string date)Keep the course and teacher guards. Use the activity diagram to check that the selected assignment has an available slot before completing it. Pass the completed attempt and course teacher to Submit, then call Learn(5). Return the completed attempt as before.
Take final three times without tutoringInspect the final assignment's Attempts elements in Watch after each attempt. Expect accuracies 66.55, 69.05, and 71.55 at indexes zero, one, and two. Submission stays null for the first two results, then refers to the third. Arthur's knowledge reaches 80.5 after the three completed attempts.
Take final once moreExpect the updated unavailable-attempt message. The three stored references, Submission, and knowledge must remain unchanged. The midterm still has its own three available slots.
Assignment.cs, add GetBestAttempt()Use the signature diagram and activity diagram. Return the actual highest-accuracy Attempt reference, or null for an empty history. Skip null elements and keep the earlier reference when accuracies tie.
Assignment.cs, add GetAttemptHistory()Use the activity diagram for the loop, empty-slot decision, exact text, and best-result suffix. Begin with the assignment name and a new line. Display slot numbers with index + 1 while continuing to access the array with index.
For a new HTML Exercises assignment, predict the name followed by Attempt 1: Available, Attempt 2: Available, and Attempt 3: Available on separate lines. There is no best-accuracy line yet. For a history with one result of 66.55, predict its F grade, two Available lines, and Best accuracy: 66.55%.
MainWindow.xaml.cs, add DisplayAssignmentHistories(Course course)Use the focused signature diagram and activity diagram. Traverse the supplied course's assignments, skip null elements, and join their returned histories with two new lines. Call the existing DisplayMessage once after the loop.
MainWindow.xaml, add the complete history buttons to their matching StackPanelsPlace the Blackboard button after tutorArthurButton. Place the Canvas button after completeTutoringButton.
<Button x:Name="blackboardHistoryButton" Content="Show Blackboard attempt history" Click="blackboardHistoryButton_Click"/>
<Button x:Name="canvasHistoryButton" Content="Show Canvas attempt history" Click="canvasHistoryButton_Click"/>
statusTextBox elementIn the opening Window element, set Title to Programming Concepts 2: Grade Book 2.2 End, Height to 650, and Width to 650. Replace the existing statusTextBox with this element in the same outer Grid location. Its fixed height and vertical scrolling make both assignment histories readable.
<TextBox x:Name="statusTextBox" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="8" Height="280" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" IsReadOnly="True"/>
MainWindow.xaml.cs, add the history click handlers inside MainWindowUse the activity diagram to implement the Blackboard handler. Declare it as private void blackboardHistoryButton_Click(object sender, RoutedEventArgs e). Create the Canvas handler using the substitutions in the table; its control flow is identical.
| Handler name | Grade book reference | Create-first message | Argument to DisplayAssignmentHistories |
|---|---|---|---|
canvasHistoryButton_Click |
this.Canvas |
Create Canvas first. |
this.Canvas.CurrentStudent.Course |
Expect Create Blackboard first. or Create Canvas first. with no exception.
Expect the correct two assignment names and three Available lines per assignment. No Best accuracy line should appear. The histories belong to separate courses.
Website 1 should show Attempt 1: 66.55% (F), two Available slots, and Best accuracy: 66.55%. HTML Exercises should still have all three slots available. Viewing history again should produce identical text.
TakeAssignment call inside takeFinalButton_ClickAdd the following expressions to Watch before pressing F11. Some expressions cannot be evaluated in this handler; leave them in Watch so you can see them become available in their declaring methods. Expand array elements to inspect fields without calling methods from Watch.
| Expression | At the handler breakpoint | Later observation |
|---|---|---|
this.Blackboard.CurrentStudent.KnowledgeLevel |
65.5 | 80.5 after three completed final attempts |
this.Blackboard.CurrentStudent.Course.Assignments |
Length 2 | Element one is Website 1 |
type |
Unavailable in this method | Final inside TakeAssignment and GetAssignmentByType |
date |
Unavailable in this method | 12/18/2018 inside TakeAssignment and CompleteAssignment |
assignment |
Unavailable in this method | Website 1 after lookup in TakeAssignment |
index |
Unavailable in this method | Loop index in GetAssignmentByType or FindAvailableAttempt |
position |
Unavailable in this method | Available-slot result in FindAvailableAttempt and Submit |
submission |
Unavailable in this method | The new Attempt parameter inside Submit |
instructor |
Unavailable in this method | Alan inside Submit |
passed |
Unavailable in this method | False after Grade returns for the first final attempt |
TakeAssignment, then GetAssignmentByTypeObserve type become Final. Follow the search from index zero to index one: Midterm does not match, Final does. Step over the matching assignment and observe result refer to Website 1. The break leaves the loop and the method returns that reference.
FindAvailableAttempt from TakeAssignmentObserve position begin at -1. At index zero the attempt slot is null; after stepping over the assignment to position, its value is zero. Follow the return to TakeAssignment. Use F10 to execute CompleteAssignment without entering it, then F11 to enter Submit.
Step over its FindAvailableAttempt call, then over Grade. Expect position zero, instructor Alan, submission.Accuracy 66.55, submission.Score 66.55, and passed false. After the array assignment executes, expand this.Attempts[0] and verify it refers to submission. this.Submission remains null because the attempt did not pass.
TakeAssignment and step over Learn(5)Knowledge becomes 70.5 after learning. The retained attempt's accuracy remains 66.55. Continue to the handler and its DisplayMessage call; the score feedback appears only when that call executes. Continue normally, then click Show Blackboard attempt history to see the stored result.
Use normal buttons for the final checks below.
The final history should retain 66.55, 69.05, and 71.55, with the best displayed as 71.55%. The midterm starts from Arthur's new knowledge of 80.5, so its first accuracy is 87.075, displayed as 87.08% (B). Its other two slots remain available. A further final request must leave both histories and knowledge unchanged.
Tutoring raises knowledge to 95 and leaves two required sessions. The final accuracy is 80.95, with grade B, and knowledge reaches 100 after practice. Its first attempt is retained as Submission; the midterm remains available. Blackboard's histories must retain their earlier results.
Canvas histories reset and Samantha returns to knowledge 87.8 with four required sessions. Blackboard stays unchanged. Confirm all original buttons and both new history buttons work, then resolve remaining build errors.