2.2 Grade Book Assignment

Grade Book 2.2 — Assignment Arrays and Attempt Histories
1.Prepare your Grade Book 2.2 project
A Copy your completed Grade Book 2.1 project, rename its folder and solution for 2.2, and open the copied solution

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.

Starting class structure.
Your completed 2.1 starting structure
  • New
  • Changed
  • Removed
Find course assignments in one collection
Acceptance Criteria
  • 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 null when no assignment matches.
2.Store the course assignments in an array
A In Course.cs, replace the Midterm and Final fields with Assignments

Use 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.

Array fields and affected method signatures.
Array fields and affected method signatures
  • New
  • Changed
  • Removed
B In both creation handlers in MainWindow.xaml.cs, initialize the two array elements

In 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.

Assignment initialization values
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
3.Find an assignment by searching the array
A In 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.

Course.GetAssignmentByType.
Search by assignment type
  • New
  • Changed
  • Removed
B Check your work: assignment selection
1 Build, create both grade books, and place a breakpoint on the return in GetAssignmentByType

Trigger 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.

2 Trace the diagram for type Quiz and for an array whose first element is null

A 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.

Keep an assignment's attempts
Acceptance Criteria
  • Each assignment begins with three available attempt slots.
  • Every completed attempt is graded and retained, including one below passing.
  • A full history prevents another attempt and another practice knowledge gain.
  • Submission refers to the highest-accuracy passing attempt; it stays null until an attempt passes.
4.Give every assignment its own attempt array
A In Assignment.cs, add and initialize Attempts using the focused class diagram

Create a three-element array in the field initializer. Keep Submission as a separate Attempt reference. Each new Assignment gets its own array.

Fresh Blackboard assignment and attempt arrays.
Fresh Blackboard arrays and their empty attempt slots
  • New
  • Changed
  • Removed
5.Find the next available attempt slot
A In 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.

Assignment.FindAvailableAttempt.
Find an empty slot or report a full history
  • New
  • Changed
  • Removed
B Check your work: available-slot cases

Trace the activity diagram for each array below. You will observe the same searches through the buttons after connecting submission.

Expected search results
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
6.Let the assignment process its submission
A In Assignment.cs, change Submit to accept the attempt and its instructor

Use 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.

B Implement Submit using its activity diagram

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.

Assignment.Submit.
Grade, retain, and select the best passing submission
  • New
  • Changed
  • Removed
C Check your work: recorded-submission decisions

Trace Submit for these independent cases. Assume an available slot and a valid instructor unless the row says otherwise.

History and Submission responsibilities
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
7.Have the student complete and submit an available attempt
A In 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.

Student.TakeAssignment.
Complete an available attempt and submit it
  • New
  • Changed
  • Removed
Take final through grading and retaining an attempt.
Follow Take final from the window into the business objects
  • New
  • Changed
  • Removed
B In the four exam handlers in MainWindow.xaml.cs, update the unavailable-attempt message

Replace the existing unavailable-assignment text with this exact message. Keep each handler's create-first guard and successful score, grade, and encouragement feedback.

Unavailable-attempt message
The assignment or its instructor is unavailable, or all three attempts have been used.
Exam handlers to update
Handler Grade book Assignment type
takeMidtermButton_Click Blackboard Midterm
takeFinalButton_Click Blackboard Final
writeEssayButton_Click Canvas Midterm
writeFinalPaperButton_Click Canvas Final
C Check your work: history storage and the limit
1 Build, create fresh Blackboard, and click Take final three times without tutoring

Inspect 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.

Blackboard after three final attempts without tutoring.
History and shared Submission reference after three final attempts
  • New
  • Changed
  • Removed
2 Click Take final once more

Expect the updated unavailable-attempt message. The three stored references, Submission, and knowledge must remain unchanged. The midterm still has its own three available slots.

Review attempts and the best result
Acceptance Criteria
  • Each grade book has its own history button.
  • History lists all three slots for each assignment, labeling an empty slot Available.
  • A completed slot shows accuracy rounded for display and its letter grade.
  • The best accuracy appears only when an assignment has a completed attempt.
  • Viewing history leaves attempts, knowledge, and tutoring requirements unchanged.
8.Find the best completed attempt
A In 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.GetBestAttempt.
Search every slot for the greatest accuracy
  • New
  • Changed
  • Removed
9.Describe an assignment's attempt history
A In 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.

Assignment.GetAttemptHistory.
Build one assignment's history text
  • New
  • Changed
  • Removed
B Check your work: history output cases

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%.

10.Display every assignment history for a course
A In 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.DisplayAssignmentHistories.
Collect the history text for the course
  • New
  • Changed
  • Removed
Display Blackboard assignment histories.
Display histories through the window
  • New
  • Changed
  • Removed
11.Connect the two history buttons
A In MainWindow.xaml, add the complete history buttons to their matching StackPanels

Place the Blackboard button after tutorArthurButton. Place the Canvas button after completeTutoringButton.

Blackboard history button
<Button x:Name="blackboardHistoryButton" Content="Show Blackboard attempt history" Click="blackboardHistoryButton_Click"/>
Canvas history button
<Button x:Name="canvasHistoryButton" Content="Show Canvas attempt history" Click="canvasHistoryButton_Click"/>
B Update the window dimensions and replace the complete statusTextBox element

In 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.

Complete history and feedback display
<TextBox x:Name="statusTextBox"
         Grid.Row="1"
         Grid.Column="0"
         Grid.ColumnSpan="3"
         Margin="8"
         Height="280"
         VerticalScrollBarVisibility="Auto"
         TextWrapping="Wrap"
         IsReadOnly="True"/>
C In MainWindow.xaml.cs, add the history click handlers inside MainWindow

Use 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.

Blackboard history handler checks that Blackboard exists before displaying its course histories.
Guard Blackboard and request its course histories
  • New
  • Changed
  • Removed
Remaining history handler
Handler name Grade book reference Create-first message Argument to DisplayAssignmentHistories
canvasHistoryButton_Click this.Canvas Create Canvas first. this.Canvas.CurrentStudent.Course
D Check your work: visible histories
1 Restart and click each history button before creating its grade book

Expect Create Blackboard first. or Create Canvas first. with no exception.

2 Create both grade books and view their histories

Expect the correct two assignment names and three Available lines per assignment. No Best accuracy line should appear. The histories belong to separate courses.

3 Recreate Blackboard, take its final once, and show its history

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.

12.Follow an attempt through Watch and stepping
A Recreate Blackboard and break on the TakeAssignment call inside takeFinalButton_Click

Add 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.

Watch expressions before stepping
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
B Step into the first final attempt and observe the changing values
1 Use F11 to enter TakeAssignment, then GetAssignmentByType

Observe 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.

2 Step into FindAvailableAttempt from TakeAssignment

Observe 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.

3 Inside Submit, inspect submission, instructor, and the assignment array

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.

4 Return to 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.

C Remove your breakpoints and recreate Blackboard and Canvas

Use normal buttons for the final checks below.

Check the completed application
13.Verify the features working together
A On fresh Blackboard, take the final three times, then take the midterm once and view history

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.

B On fresh Canvas, complete Samantha tutoring, write the final paper once, and view Canvas history

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.

C Recreate Canvas, view its empty histories, compare the ending structure, and build

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.

Ending class structure.
Ending structure with New, Changed, and Removed markers
  • New
  • Changed
  • Removed