Roles in Submission, Teaching, and Grading
Unit 3 & 4 · Class Creation + Data Collections · 5 minutes
The Open Coding Society Submissions page shows three different views of the same data: students see only their own work, teachers see submissions to assignments they created, and admins see everything. This lesson builds a small Java model of that system using a Unit 3 class and a Unit 4 ArrayList, then filters it by role the same way the real site does.
Learning Objective and Success Criteria
ArrayList and iterate over themThis lesson does not touch the real Submissions database or API. It builds a small, self-contained Java model of the same idea so you can practice Unit 3 and Unit 4 skills before looking at the production code in _layouts/submissions.html and assets/js/submissions/creator-dashboard.js.
Trace the Submissions Data
The live Submissions page (/submissions) has three tabs, and each tab is really the same list of submissions, filtered a different way:
| Tab | Who sees it | Filter rule |
|---|---|---|
| My Submissions | Every logged-in user | Keep only submissions where submitterId matches the viewer |
| Assignments You Created | Any teacher who authored an assignment | Keep only submissions whose assignment is owned by the viewer |
| All Submissions | Admins only | Keep every submission — no filter |
In this lesson, Role and userId stand in for “which tab is open and who is logged in,” and a List<Submission> stands in for the rows the server would normally send back.
Read the Java Algorithm
Submission is a Unit 3 class: a constructor sets four fields, and there are no other methods yet. visibleSubmissionsFor is the Unit 4 half of the lesson: it walks a List<Submission> with an enhanced for loop and uses if/else if selection to decide whether each submission belongs in the filtered result, based on the caller’s Role.
Code Runner Challenge
Run the three role checks, then change a submitterId or assignmentOwnerId and predict the new counts.
View IPYNB Source
// CODE_RUNNER: Run the three role checks, then change a submitterId or assignmentOwnerId and predict the new counts.
import java.util.ArrayList;
import java.util.List;
public class SubmissionRoles {
enum Role { STUDENT, TEACHER, ADMIN }
static class Submission {
int id;
int submitterId;
int assignmentOwnerId;
Double grade;
Submission(int id, int submitterId, int assignmentOwnerId, Double grade) {
this.id = id;
this.submitterId = submitterId;
this.assignmentOwnerId = assignmentOwnerId;
this.grade = grade;
}
}
public static List<Submission> visibleSubmissionsFor(
List<Submission> allSubmissions, Role role, int userId) {
List<Submission> visible = new ArrayList<>();
for (Submission submission : allSubmissions) {
if (role == Role.ADMIN) {
visible.add(submission);
} else if (role == Role.TEACHER && submission.assignmentOwnerId == userId) {
visible.add(submission);
} else if (role == Role.STUDENT && submission.submitterId == userId) {
visible.add(submission);
}
}
return visible;
}
public static void main(String[] args) {
List<Submission> allSubmissions = new ArrayList<>();
allSubmissions.add(new Submission(1, 101, 201, null));
allSubmissions.add(new Submission(2, 102, 201, 0.9));
allSubmissions.add(new Submission(3, 101, 202, null));
allSubmissions.add(new Submission(4, 103, 202, 1.0));
System.out.println("Student 101 sees: " + visibleSubmissionsFor(allSubmissions, Role.STUDENT, 101).size());
System.out.println("Teacher 201 sees: " + visibleSubmissionsFor(allSubmissions, Role.TEACHER, 201).size());
System.out.println("Admin sees: " + visibleSubmissionsFor(allSubmissions, Role.ADMIN, 0).size());
}
}
SubmissionRoles.main(null);
Popcorn Check
Submission #1 has submitterId = 101 and assignmentOwnerId = 201. Does Teacher 201 see it as a graded submission?
Teacher 201 sees it because assignmentOwnerId matches, but its grade field is null, so on the real site it would show a “Pending Review” badge, not a grade.
Why does the ADMIN branch come first in the if/else if chain?
An admin’s userId will not usually match either submitterId or assignmentOwnerId for every row, so checking ADMIN first guarantees admins always see every submission regardless of ID values.
Security boundary: this method only decides what a role is shown. On the real Open Coding Society backend, every submissions API endpoint must also check the caller’s role and identity on the server before returning data — filtering only in the browser would let anyone request the admin endpoint directly and see every student’s submissions.
Homework Hacks
Three hacks · 5 minutes each
Each starter compiles before you edit it, so you can run the initial version and compare its incorrect output with the expected output. Change only the requested method.
Homework Hack 1 — Add a Status Method to the Class (5 minutes)
class creation Complete the Submission class by adding a status() method. Return "graded" when grade is not null, and "pending" otherwise.
Code Runner Challenge
Finish status() so both checks print true.
View IPYNB Source
// CODE_RUNNER: Finish status() so both checks print true.
public class SubmissionStatusHack {
static class Submission {
Double grade;
Submission(Double grade) {
this.grade = grade;
}
String status() {
// TODO: return "graded" when grade is not null, otherwise "pending".
return "not implemented";
}
}
public static void main(String[] args) {
Submission graded = new Submission(0.85);
Submission pending = new Submission(null);
System.out.println("graded".equals(graded.status()));
System.out.println("pending".equals(pending.status()));
}
}
SubmissionStatusHack.main(null);
Homework Hack 2 — Count Pending Submissions (5 minutes)
data collections Complete countPending. Iterate through submissions and return how many have a null grade.
Code Runner Challenge
Add a loop so the check prints true.
View IPYNB Source
// CODE_RUNNER: Add a loop so the check prints true.
import java.util.ArrayList;
import java.util.List;
public class PendingCountHack {
static class Submission {
Double grade;
Submission(Double grade) {
this.grade = grade;
}
}
public static int countPending(List<Submission> submissions) {
// TODO: iterate through submissions and count the ones with grade == null.
return -1;
}
public static void main(String[] args) {
List<Submission> submissions = new ArrayList<>();
submissions.add(new Submission(null));
submissions.add(new Submission(0.75));
submissions.add(new Submission(null));
System.out.println(countPending(submissions) == 2);
}
}
PendingCountHack.main(null);
Homework Hack 3 — Filter Submissions by Role (5 minutes)
combined algorithm Complete visibleSubmissionsFor. Combine iteration and selection: an ADMIN sees every submission, a TEACHER sees submissions whose assignmentOwnerId matches userId, and a STUDENT sees submissions whose submitterId matches userId.
Code Runner Challenge
Combine a loop with role-based selection so all three checks print true.
View IPYNB Source
// CODE_RUNNER: Combine a loop with role-based selection so all three checks print true.
import java.util.ArrayList;
import java.util.List;
public class RoleFilterHack {
enum Role { STUDENT, TEACHER, ADMIN }
static class Submission {
int submitterId;
int assignmentOwnerId;
Submission(int submitterId, int assignmentOwnerId) {
this.submitterId = submitterId;
this.assignmentOwnerId = assignmentOwnerId;
}
}
public static List<Submission> visibleSubmissionsFor(
List<Submission> allSubmissions, Role role, int userId) {
List<Submission> visible = new ArrayList<>();
// TODO: iterate through allSubmissions.
// TODO: use role and userId to decide whether each submission belongs in visible.
return visible;
}
public static void main(String[] args) {
List<Submission> allSubmissions = new ArrayList<>();
allSubmissions.add(new Submission(101, 201));
allSubmissions.add(new Submission(102, 201));
allSubmissions.add(new Submission(103, 202));
System.out.println(visibleSubmissionsFor(allSubmissions, Role.STUDENT, 101).size() == 1);
System.out.println(visibleSubmissionsFor(allSubmissions, Role.TEACHER, 201).size() == 2);
System.out.println(visibleSubmissionsFor(allSubmissions, Role.ADMIN, 0).size() == 3);
}
}
RoleFilterHack.main(null);
Submission Checklist and Grading
The three hacks are worth 1 point total.
- 0.3 — Hack 1:
status()correctly returns"graded"or"pending"based on thegradefield - 0.3 — Hack 2:
countPendingiterates the list and returns the correct count - 0.4 — Hack 3: iteration and role-based selection correctly filter all three roles
Before submitting, run each homework cell and confirm every printed check is true. Do not commit real student names, grades, or submission content in your work.
Lesson Design and Revision
Learner need: Students can describe “roles” in the abstract but struggle to see how a UI with three tabs (My Submissions, Assignments You Created, All Submissions) maps onto ordinary Unit 3 and Unit 4 Java code.
Feedback applied: Ground every code example in the real Submissions page instead of an invented scenario, so students can open _layouts/submissions.html and assets/js/submissions/creator-dashboard.js afterward and recognize the same filtering logic.
Revision made: The lesson builds one small Submission class and one List<Submission>, then reuses that same model across the worked example and all three homework hacks, so students practice the class-plus-collection pattern from four different angles instead of four unrelated examples.
References
- College Board. (2025). AP Computer Science A course and exam description: Unit 3, Class Creation, and Unit 4, Data Collections. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description.pdf
- Open Coding Society. (2026). Submissions dashboard [Web application feature]. https://pages.opencodingsociety.com/submissions
Submit Assignment
Need to update a submission later? Open the submissions dashboard.