-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignments-export.json
More file actions
181 lines (181 loc) · 107 KB
/
Copy pathassignments-export.json
File metadata and controls
181 lines (181 loc) · 107 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
{
"exported_at": "2026-04-29T19:45:29.562Z",
"assignments": [
{
"title": "Selection and Insertion Sort",
"prompt": "Complete both sorts. Use this starter code:\n```java\npublic class InsertionSelectionQuiz {\n\n\tpublic static void selectionSort(int[] list){\n\n\n\t}\n\tpublic static void insertionSort(int[] list){\n\n\n\t}\n\tpublic static void shuffleArray(int[] list){\n\t\tfor(int pass = 0; pass < list.length; pass++){\n\t\t\tint smallest =(int) Math.random()*list.length;\n\t\t\tint temp = list[pass];\n\t\t\tlist[pass] = list[smallest];\n\t\t\tlist[smallest] = temp;\n\t\t}\n\t}\n\tpublic static void viewArray(int[] list){\n\t\tfor(int x: list){\n\t\t\tSystem.out.print(x + \"\\t\");\n\t\t}\n\t\tSystem.out.println();\n\t}\t\t\n\tpublic static void main(String[] args) {\n\t\tint[] lost = new int[]{2,5,7,1,32,8,0};\n\t\tSystem.out.println(\"Insertion Sort\");\n\t\tviewArray(lost);\n\t\tinsertionSort(lost);\n\t\tviewArray(lost);\n\t\tshuffleArray(lost);\n\t\tSystem.out.println(\"Selection Sort\");\n\t\tviewArray(lost);\n\t\tselectionSort(lost);\n\t\tviewArray(lost);\n\t}\n\n}\n```",
"rubric": "Rubric: total 15 points\n1 point for indenting\nselectionSort - 7 points\n 1 point outer loop correct\n 1 point assigning initial location of smallest\n 1 point initial value of i (counter for while loop)\n 1 point correct if statement\n 1 point reassign smallest in if statement\n 2 points swap correctly\n\ninsertionSort - 7 points\n 1 point outer loop correct\n 1 point assigning initial value of temp\n 2 point inner loop correct (-1 if don't utilize short circuit evaluation)\n 1 point sliding value in list\n 1 point decrement counter\n 1 point insert value into correct location",
"max_submissions": 1,
"is_visible": 0,
"tab_monitoring_enabled": 1
},
{
"title": "Selection and Insertion Sorts - Strings",
"prompt": "Complete both sorts. Use this starter code:\n```java\npublic class InsertionSelectionQuiz {\n\n\tpublic static void selectionSort(String[] list){\n\n\n\t}\n\tpublic static void insertionSort(String[] list){\n\n\n\t}\n\tpublic static void shuffleArray(String[] list){\n\t\tfor(int pass = 0; pass < list.length; pass++){\n\t\t\tint smallest =(int) Math.random()*list.length;\n\t\t\tString temp = list[pass];\n\t\t\tlist[pass] = list[smallest];\n\t\t\tlist[smallest] = temp;\n\t\t}\n\t}\n\tpublic static void viewArray(String[] list){\n\t\tfor(String x: list){\n\t\t\tSystem.out.print(x + \"\\t\");\n\t\t}\n\t\tSystem.out.println();\n\t}\t\t\n\tpublic static void main(String[] args) {\n\t\tString[] lost = new String[]{\"Ed\",\"Bo\",\"Ty\",\"Jo\",\"Vi\",\"Do\",\"Em\",\"Ru\",\"Oz\"};\n\t\tSystem.out.println(\"Insertion Sort\");\n\t\tviewArray(lost);\n\t\tinsertionSort(lost);\n\t\tviewArray(lost);\n\t\tshuffleArray(lost);\n\t\tSystem.out.println(\"Selection Sort\");\n\t\tviewArray(lost);\n\t\tselectionSort(lost);\n\t\tviewArray(lost);\n\t}\n\n}\n```",
"rubric": "Rubric: total 15 points\n1 point for indenting\nselectionSort - 7 points\n 1 point outer loop correct\n 1 point assigning initial location of smallest\n 1 point initial value of i (counter for while loop)\n 1 point correct if statement\n 1 point reassign smallest in if statement\n 2 points swap correctly\n\ninsertionSort - 7 points\n 1 point outer loop correct\n 1 point assigning initial value of temp\n 2 point inner loop correct (-1 if don't utilize short circuit evaluation)\n 1 point sliding value in list\n 1 point decrement counter\n 1 point insert value into correct location",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "Array Practice Assignment",
"prompt": "Write a class that includes each of the following static methods. The main() should test each of these methods.\n```java\npublic class ArrayPractice{\n\n\t\tpublic static void viewList(int[] list){\n\t\t }\n\t\tpublic static void viewList(double[] list){\n\t\t }\n\t\tpublic static void fillWithRandomInts(int[] list, int min, int max){\n\t\t }\n\t\tpublic static void fillWithRandomDoubles(double[] list, double min, double max){\n\t\t }\n\t\tpublic static int minimum(int[] list){\n\t\t return 0;\n\t\t }\n\t\tpublic static int maximum(int[] list){\n\t\t return 0;\n\t\t }\n\t\tpublic static double mean(int[] list){\n\t\t return 0.0;\n\t\t }\n\t\tpublic static double median(int[] list){\n\t\t return 0.0;\n\t\t }\n\t\tpublic static void swap(int[] list, int index1, int index2){\n\t\t }\n\t\tpublic static void modifyByDoubling(int[] list){\n\t\t }\n\t\t public static int[] createFreqTable(int[] list){\n\t\t return new int[0];\n\t\t }\n\t\t public static int mode(int[] list){\n\t\t return 0;\n\t\t }\n\t\tpublic static int sequentialSearch(int[] list, int target){\n\t\t return -1;\n\t\t }\n\t\tpublic static int[] searchForAll(int[] list, int target){\n\t\t return new int[0];\n\t\t }\n\t\tpublic static void append(int[] list, int item){\n\t\t }\n\t\tpublic static void selectionSort(double[] list){\n\t\t }\n\t\tpublic static void selectionSortMax(double[] list){\n\t\t }\n\n\t\t public static void main(String[] args) {\n\t\t System.out.println(\"Hello, World!\");\n\t\t }\n\t\t}}\n```",
"rubric": "For each of the following methods assign the following 3 points:\n - 2 points for the method working correctly\n - 1 point for testing in the main at least once\ntotal of 17 methods for 51 points\nviewList(int[])\nviewList(double[])\nfillWithRandomInts(int[], int, int)\nfillWithRandomDoubles(double[], double, double)\nminimum(int[])\nmaximum(int[])\nmean(int[])\nmedian(int[])\nswap(int[], int, int)\nmodifyByDoubling(int[])\ncreateFreqTable(int[])\nmode(int[])\nsequentialSearch(int[], int)\nsearchForAll(int[], int)\nappend(int[], int)\nselectionSort(double[])\nselectionSortMax(double[])",
"max_submissions": 3,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "Practice Array Methods - Frequency and String Length",
"prompt": "Complete the following methods:\n```java\n //returns a list of integers representing the length of the corresponding String\n public static int[] getLengths(String[] sList){ \n\n }\n //list contains integers 0 - 20. Method returns an array of size 21 that holds the frequencies of each integer\n public static int[] getFrequencies(int[] list) {\n\n }\n //write a main to test each method",
"rubric": "getLengths method:\n -1 point creation of new array of ints\n -2 points looping correctly through the initial list and putting the length in the corresponding array\n -1 point returning correct array\ngetFrequencies method:\n -1 point creation of new array of ints\n -2 points looping correctly through the initial list and incrementing the correct element of the corresponding array\n -1 point returning correct array\nmain()\n -1 point for testing the method getLengths\n -1 point for testing the method getFrequencies",
"max_submissions": 2,
"is_visible": 1,
"tab_monitoring_enabled": 0
},
{
"title": "Array Practice from CodingBat",
"prompt": "Return an array that is \"left shifted\" by one -- so {6, 2, 5, 3} returns {2, 5, 3, 6}. You may modify and return the given array, or return a new array.\nshiftLeft([6, 2, 5, 3]) → [2, 5, 3, 6]\nshiftLeft([1, 2]) → [2, 1]\nshiftLeft([1]) → [1]\n\n\nGiven two arrays of ints sorted in increasing order, outer and inner, return true if all of the numbers in inner appear in outer. The best solution makes only a single \"linear\" pass of both arrays, taking advantage of the fact that both arrays are already in sorted order.\nlinearIn([1, 2, 4, 6], [2, 4]) → true\nlinearIn([1, 2, 4, 6], [2, 3, 4]) → false\nlinearIn([1, 2, 4, 4, 6], [2, 4]) → true\n\nReturn an array that contains exactly the same numbers as the given array, but rearranged so that every 3 is immediately followed by a 4. Do not move the 3's, but every other number may move. The array contains the same number of 3's and 4's, every 3 has a number after it that is not a 3, and a 3 appears in the array before any 4.\nfix34([1, 3, 1, 4]) → [1, 3, 4, 1]\nfix34([1, 3, 1, 4, 4, 3, 1]) → [1, 3, 4, 1, 1, 3, 4]\nfix34([3, 2, 2, 4]) → [3, 4, 2, 2]\n\n```java\npublic int[] shiftLeft(int[] nums) {\n \n}\npublic boolean linearIn(int[] outer, int[] inner) {\n \n}\npublic int[] fix34(int[] nums) {\n \n}",
"rubric": "1 point for indenting correctly\n1.5 points for testing methods with main()\n2.5 points for each method",
"max_submissions": 2,
"is_visible": 1,
"tab_monitoring_enabled": 0
},
{
"title": "Quiz: Arrays and ArrayLists",
"prompt": "1. Write a Bubble sort that accepts an ArrayList\\<String> called list.\nYour sort does NOT need to include a quick out feature.\n```java\npublic static void bubbleSort(ArrayList<String> list)\n```\n\n2. Complete the following method:\n```java\npublic static int[] insertInOrder(int[] list, int numToBeInserted) \n//precondition: list is sorted requirement: must work in O(n) time complexity\n\n```\n\n3. Complete the following method. The length of the returned list should match the number of times the target is found. For example, if the target is not found, return an empty list.\n\n```java\npublic static ArrayList<Integer> searchForMultiple(ArrayList<Integer> list, int target)\n```\n4. Test each method in the main()",
"rubric": "searchForMultiple method - 4 points\nbubbleSort method - 4 points\ninsertInOrder method - 4 points\nmain() method - 3 points (1 point for testing each method)",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "Quiz: 2D Array Methods 1",
"prompt": "Complete the three methods that are required to run the following main() method:\n```java\npublic static void main(String[] args) {\n int[][] arr = new int[][]{{3,4,5,6},{7,2,9,4},{1,2,3,5}};\n viewMatrix(arr);\n System.out.println();\n swapRows(arr, 0, 2);\n viewMatrix(arr);\n System.out.println();\n swapColumns(arr, 0, 2);\n viewMatrix(arr);\n}",
"rubric": "viewMatrix - 4 points\nswapRows - 3 points\nswapColumns - 3 points",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "Recursion Practice from CodingBat",
"prompt": "Complete as many Recursion-1 practice problems as possible. Complete them in CodingBat and here (use AI help if you wish). \n* Paste in the description of the problem as a comment before the method.\n* Write a minimum of 2 test cases in the main for each method.",
"rubric": "Total number of successful methods. No denominator.",
"max_submissions": null,
"is_visible": 1,
"tab_monitoring_enabled": 0
},
{
"title": "CodingBat Recursion",
"prompt": "METHOD 1 - endX:\nGiven a string, compute recursively a new string where all the lowercase 'x' chars have been moved to the end of the string.\n```java\nendX(\"xxre\") → \"rexx\"\nendX(\"xxhixx\") → \"hixxxx\"\nendX(\"xhixhix\") → \"hihixxx\"\n```\nMETHOD 2 - powerN:\nGiven base and n that are both 1 or more, compute recursively (no loops) the value of base to the n power, so powerN(3, 2) is 9 (3 squared).\n```java\npowerN(3, 1) → 3\npowerN(3, 2) → 9\npowerN(3, 3) → 27\n```\nMAIN()\nWrite at least 3 tests for each method in the main()\n```java\npublic class RecursionQuiz{\n public static String endX(String str) {\n \n }\n public static int powerN(int base, int n) {\n \n }\n public static void main(String [] args){\n\n }\n}",
"rubric": "4 points Method 1\n4 points Method 2\n Note for powerN: accept n==0 or n==1 as correct base cases\n2 points Main",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Review: Student Elective Scheduling - from Class Handout",
"prompt": "```java\nimport java.util.ArrayList;\n\n// ─────────────────────────────────────────────\n// Elective class\n// ─────────────────────────────────────────────\nclass Elective {\n private String name;\n private int maxClassSize;\n private int classSize;\n\n public Elective(String name, int maxClassSize, int currentEnrollment) {\n this.name = name;\n this.maxClassSize = maxClassSize;\n this.classSize = currentEnrollment;\n }\n\n public String getName() { return name; }\n public int getMaxClassSize() { return maxClassSize; }\n public int getClassSize() { return classSize; }\n\n public void addStudent(Student s) {\n // precondition: classSize < maxClassSize, s != null\n classSize++;\n }\n\n @Override\n public String toString() {\n return String.format(\"%-20s max=%-3d current=%-3d %s\",\n name, maxClassSize, classSize,\n (classSize >= maxClassSize ? \"[FULL]\" : \"[open]\"));\n }\n}\n\n// ─────────────────────────────────────────────\n// Student class\n// ─────────────────────────────────────────────\nclass Student {\n private String name;\n private String[] choices; // choices[0..2]\n private Elective assignedElective;\n\n public Student(String name, String choice0, String choice1, String choice2) {\n this.name = name;\n this.choices = new String[]{choice0, choice1, choice2};\n this.assignedElective = null;\n }\n\n // precondition: 0 <= index < 3\n public String getChoice(int index) { return choices[index]; }\n\n public boolean hasElective() { return assignedElective != null; }\n\n // precondition: e != null\n public void assignElective(Elective e) { assignedElective = e; }\n\n public String getName() { return name; }\n\n @Override\n public String toString() {\n String assigned = hasElective() ? assignedElective.getName() : \"-- UNASSIGNED --\";\n return String.format(\"%-12s choices: [%s, %s, %s] => %s\",\n name, choices[0], choices[1], choices[2], assigned);\n }\n}\n\n// ─────────────────────────────────────────────\n// School class (contains the three FRQ methods)\n// ─────────────────────────────────────────────\nclass School {\n private ArrayList<Student> studentList;\n private ArrayList<Elective> electiveList;\n\n public School(ArrayList<Student> students, ArrayList<Elective> electives) {\n this.studentList = students;\n this.electiveList = electives;\n }\n\n private int getStudentListSize() { return studentList.size(); }\n private int getElectiveListSize() { return electiveList.size(); }\n\n // ── Part (a) ──────────────────────────────────────────────────────────\n // precondition: name is the name of an Elective in electiveList\n // postcondition: returns the Elective in electiveList with the given name\n private Elective getElectiveByName(String name) {\n\n }\n\n // ── Part (b) ──────────────────────────────────────────────────────────\n // postcondition: All Students in studentList have been either assigned\n // their first available elective choice or not assigned;\n // All Electives in electiveList have been updated\n // appropriately as Students are assigned to them.\n public void assignElectivesToStudents() {\n\n }\n\n // ── Part (c) ──────────────────────────────────────────────────────────\n // postcondition: returns a list of those Students who have not been\n // assigned an Elective\n public ArrayList<Student> studentsWithoutElectives() {\n\n }\n\n // ── Convenience accessor for printing ─────────────────────────────────\n public ArrayList<Elective> getElectiveList() { return electiveList; }\n public ArrayList<Student> getStudentList() { return studentList; }\n}\n\n// ─────────────────────────────────────────────\n// Driver\n// ─────────────────────────────────────────────\npublic class SchoolDriver {\n\n public static void main(String[] args) {\n\n // ── Build electives with enrollments AFTER 64 students assigned ──\n ArrayList<Elective> electives = new ArrayList<Elective>();\n electives.add(new Elective(\"Astronomy\", 12, 12)); // FULL\n electives.add(new Elective(\"Ballroom Dance\", 20, 3));\n electives.add(new Elective(\"Basketweaving\", 15, 14)); // 1 spot left\n electives.add(new Elective(\"Constitutional Law\", 10, 7));\n electives.add(new Elective(\"Marine Biology\", 10, 10)); // FULL\n electives.add(new Elective(\"Programming\", 30, 30)); // FULL\n\n // ── Build students in lottery order ──────────────────────────────\n ArrayList<Student> students = new ArrayList<Student>();\n // name choice0 choice1 choice2\n students.add(new Student(\"Andrew\", \"Programming\", \"Marine Biology\", \"Ballroom Dance\"));\n students.add(new Student(\"David\", \"Constitutional Law\", \"Basketweaving\", \"Programming\"));\n students.add(new Student(\"Elizabeth\",\"Marine Biology\", \"Programming\", \"Astronomy\"));\n students.add(new Student(\"Ethan\", \"Basketweaving\", \"Marine Biology\", \"Astronomy\"));\n students.add(new Student(\"Katharine\",\"Programming\", \"Basketweaving\", \"Marine Biology\"));\n\n School school = new School(students, electives);\n\n // ── Print initial state ───────────────────────────────────────────\n System.out.println(\"╔══════════════════════════════════════════════════════╗\");\n System.out.println(\"║ INITIAL ELECTIVE ENROLLMENT ║\");\n System.out.println(\"╚══════════════════════════════════════════════════════╝\");\n for (Elective e : school.getElectiveList()) {\n System.out.println(\" \" + e);\n }\n\n System.out.println(\"\\n╔══════════════════════════════════════════════════════╗\");\n System.out.println(\"║ STUDENTS TO BE ASSIGNED ║\");\n System.out.println(\"╚══════════════════════════════════════════════════════╝\");\n for (Student s : school.getStudentList()) {\n System.out.printf(\" %-12s [%s, %s, %s]%n\",\n s.getName(), s.getChoice(0), s.getChoice(1), s.getChoice(2));\n }\n\n // ── Run Part (b) ─────────────────────────────────────────────────\n school.assignElectivesToStudents();\n\n // ── Print results ─────────────────────────────────────────────────\n System.out.println(\"\\n╔══════════════════════════════════════════════════════╗\");\n System.out.println(\"║ ASSIGNMENT RESULTS ║\");\n System.out.println(\"╚══════════════════════════════════════════════════════╝\");\n for (Student s : school.getStudentList()) {\n System.out.println(\" \" + s);\n }\n\n System.out.println(\"\\n╔══════════════════════════════════════════════════════╗\");\n System.out.println(\"║ FINAL ELECTIVE ENROLLMENT ║\");\n System.out.println(\"╚══════════════════════════════════════════════════════╝\");\n for (Elective e : school.getElectiveList()) {\n System.out.println(\" \" + e);\n }\n\n // ── Run Part (c) ─────────────────────────────────────────────────\n ArrayList<Student> unassigned = school.studentsWithoutElectives();\n System.out.println(\"\\n╔══════════════════════════════════════════════════════╗\");\n System.out.println(\"║ STUDENTS WITHOUT AN ELECTIVE ║\");\n System.out.println(\"╚══════════════════════════════════════════════════════╝\");\n if (unassigned.isEmpty()) {\n System.out.println(\" All students were successfully assigned.\");\n } else {\n for (Student s : unassigned) {\n System.out.println(\" \" + s.getName());\n }\n }\n\n // ── Expected output per problem statement ─────────────────────────\n System.out.println(\"\\n╔══════════════════════════════════════════════════════╗\");\n System.out.println(\"║ EXPECTED (per problem) ║\");\n System.out.println(\"╚══════════════════════════════════════════════════════╝\");\n System.out.println(\" Andrew => Ballroom Dance (1st+2nd full)\");\n System.out.println(\" David => Constitutional Law (1st open)\");\n System.out.println(\" Elizabeth=> UNASSIGNED (all 3 full)\");\n System.out.println(\" Ethan => Basketweaving (1st had 1 spot)\");\n System.out.println(\" Katharine=> UNASSIGNED (all 3 now full)\");\n }\n}\n```",
"rubric": "none",
"max_submissions": null,
"is_visible": 1,
"tab_monitoring_enabled": 0
},
{
"title": "Quiz: Strings AP Part 2 Question",
"prompt": "# AP Computer Science A — Free Response Question\n## CourseRecord — String Methods\n**Part B Style | Strings | 10 points total**\n\n---\n\n## Background\n\nA school district stores each student's course record as a single formatted `String`. The record follows this exact structure:\n\n```\n\"LastName,FirstName|student@schooldomain.edu|score1,score2,score3,score4\"\n```\n\nFor example, the record for a student named Maria Johnson with email `mjohnson@westlake.edu` and four quiz scores might look like:\n\n```\n\"Johnson,Maria|mjohnson@westlake.edu|88,92,76,95\"\n```\n\nThe pipe character (`|`) separates the three sections of the record:\n\n| Section | Description | Example |\n|---------|-------------|---------|\n| Section 1 | `LastName,FirstName` | `Johnson,Maria` |\n| Section 2 | email address | `mjohnson@westlake.edu` |\n| Section 3 | four comma-separated scores | `88,92,76,95` |\n\nThe `CourseRecord` class stores one such record and provides methods to extract and process the data. You will write three methods for this class. You may assume that all records are correctly formatted and that there are always exactly four scores, each a valid integer.\n\n---\n\n## Part A — `getLastName()` *(3 points)*\n\nWrite the `getLastName` method. This method returns the student's last name, which is the portion of the record that appears **before the first comma**.\n\n**Examples:**\n\n| `record` value | `getLastName()` returns |\n|----------------|------------------------|\n| `\"Johnson,Maria\\|mjohnson@westlake.edu\\|88,92,76,95\"` | `\"Johnson\"` |\n| `\"Smith,Alex\\|asmith@lakeview.edu\\|70,82,88,91\"` | `\"Smith\"` |\n| `\"De La Cruz,Sam\\|sdelacruz@eastside.edu\\|95,99,94,97\"` | `\"De La Cruz\"` |\n\nComplete the `getLastName` method in the starter code.\n\n---\n\n## Part B — `getFormattedName()` *(3 points)*\n\nWrite the `getFormattedName` method. This method returns the student's full name formatted as `\"FirstName LastName\"` — first name, then a space, then last name.\n\n- The **last name** appears before the first comma.\n- The **first name** appears between the first comma and the first pipe character (`|`).\n\n**Examples:**\n\n| `record` value | `getFormattedName()` returns |\n|----------------|------------------------------|\n| `\"Johnson,Maria\\|mjohnson@westlake.edu\\|88,92,76,95\"` | `\"Maria Johnson\"` |\n| `\"Smith,Alex\\|asmith@lakeview.edu\\|70,82,88,91\"` | `\"Alex Smith\"` |\n| `\"De La Cruz,Sam\\|sdelacruz@eastside.edu\\|95,99,94,97\"` | `\"Sam De La Cruz\"` |\n\nComplete the `getFormattedName` method in the starter code.\n\n---\n\n## Part C — `getAverageScore()` *(4 points)*\n\nWrite the `getAverageScore` method. The scores are the four comma-separated integers that appear **after the second pipe character**. This method returns the average of those four scores as a `double`.\n\n> **Required:** You **must** use the `split()` method in your solution. A solution that does not call `split()` will receive 0 points for Part C, even if the output is correct.\n\n**Method reference (not on the AP Quick Reference):**\n\n```java\nString[] split(String delimiter)\n```\nSplits a string around each occurrence of the delimiter and returns an array of the parts.\n\n```java\n\"88,92,76,95\".split(\",\") → {\"88\", \"92\", \"76\", \"95\"}\n```\n\nYou may also use `Integer.parseInt(String s)` to convert a `String` to an `int`.\n\n**Examples:**\n\n| `record` value | `getAverageScore()` returns |\n|----------------|-----------------------------|\n| `\"Johnson,Maria\\|mjohnson@westlake.edu\\|88,92,76,95\"` | `87.75` |\n| `\"Smith,Alex\\|asmith@lakeview.edu\\|70,82,88,91\"` | `82.75` |\n| `\"De La Cruz,Sam\\|sdelacruz@eastside.edu\\|95,99,94,97\"` | `96.25` |\n\nComplete the `getAverageScore` method in the starter code.\n\n---\n\n*Use the provided starter code to write and test your solutions. Run the `main` method to verify your output matches the expected values.*\n\n\n```java\npublic class CourseRecord\n{\n private String record;\n\n public CourseRecord(String record)\n {\n this.record = record;\n }\n\n // ── PART A ────────────────────────────────────────\n // Returns the student's last name.\n // The last name appears before the first comma.\n public String getLastName()\n {\n // YOUR CODE HERE\n\n\n }\n\n // ── PART B ────────────────────────────────────────\n // Returns the full name as \"FirstName LastName\".\n // First name is between the comma and the first '|'.\n public String getFormattedName()\n {\n // YOUR CODE HERE\n\n\n }\n\n // ── PART C ────────────────────────────────────────\n // Returns the average of the four scores as a double.\n // Scores are after the second '|', separated by commas.\n // You MUST use split() in your solution.\n public double getAverageScore()\n {\n // YOUR CODE HERE\n\n\n }\n\n // ── TEST MAIN (do not modify) ──────────────────────\n public static void main(String[] args)\n {\n CourseRecord r1 = new CourseRecord(\n \"Johnson,Maria|mjohnson@westlake.edu|88,92,76,95\");\n CourseRecord r2 = new CourseRecord(\n \"Smith,Alex|asmith@lakeview.edu|70,82,88,91\");\n CourseRecord r3 = new CourseRecord(\n \"De La Cruz,Sam|sdelacruz@eastside.edu|95,99,94,97\");\n\n System.out.println(\"=== Part A: getLastName() ===\");\n System.out.println(\"r1 → Expected: Johnson | Actual: \" + r1.getLastName());\n System.out.println(\"r2 → Expected: Smith | Actual: \" + r2.getLastName());\n System.out.println(\"r3 → Expected: De La Cruz | Actual: \"+ r3.getLastName());\n\n System.out.println(\"\\n=== Part B: getFormattedName() ===\");\n System.out.println(\"r1 → Expected: Maria Johnson | Actual: \" + r1.getFormattedName());\n System.out.println(\"r2 → Expected: Alex Smith | Actual: \" + r2.getFormattedName());\n System.out.println(\"r3 → Expected: Sam De La Cruz | Actual: \" + r3.getFormattedName());\n\n System.out.println(\"\\n=== Part C: getAverageScore() ===\");\n System.out.println(\"r1 → Expected: 87.75 | Actual: \" + r1.getAverageScore());\n System.out.println(\"r2 → Expected: 82.75 | Actual: \" + r2.getAverageScore());\n System.out.println(\"r3 → Expected: 96.25 | Actual: \" + r3.getAverageScore());\n }\n}",
"rubric": "AP Computer Science A · Scoring Rubric — Teacher Copy\nCourseRecord — Rubric\n10 points total · Do not share with students before grading\nPART A\ngetLastName() — 3 points\n1\nCalls indexOf(\",\") (or equivalent, which could be a loop or split()) to correctly locate the first comma in record.\n1\nCalls substring() with the correct start index (0) and end index (the comma position) to extract the last name. (Unless using split())\n1\nReturns the resulting String (correct return type and value).\nCommon errors: Off-by-one in substring (e.g., indexOf(\",\")+1 as end index). Using charAt instead of substring and returning a char.\nPART B\ngetFormattedName() — 3 points\n1\nCorrectly isolates the last name (before comma) AND correctly isolates the first name (between comma+1 and first pipe). Both indices must be computed; partial credit is not awarded for only one name. \n1\nUses indexOf(\"|\") to locate the first pipe character as the upper bound for extracting the first name.\n1\nReturns the result in \"FirstName LastName\" order with exactly one space in between (e.g., firstName + \" \" + lastName).\nCommon errors: Returning \"LastName FirstName\" (reversed). Missing the space. Using a hardcoded index instead of indexOf.\nAlso acceptable - multiple uses of split(), using commas and pipes\nPART C\ngetAverageScore() — 4 points\n1\nCorrectly isolates the scores section: extracts the substring after the second |. Acceptable approaches: (a) chain two indexOf/substring calls; (b) find the last pipe via repeated indexOf.\n1\nCalls split(\",\") on the scores section to produce a String[]. This point is required by the problem — no split() = max 2 points for Part C regardless of correct output.\n1\nCorrectly traverses the array (using a for loop or enhanced for) and accumulates the sum using Integer.parseInt() on each element.\n1\nReturns the correct double average: sum divided by the array length. Division must produce a decimal result (not integer division).\nCommon errors: Integer division (sum / scores.length where both are int → truncates). Not isolating the scores section first and splitting the entire record. Hardcoding / 4 instead of / scores.length (deduct point 4 — lacks generality).\nPenalty: If a student does not use split(), award 0 points for Part C even if the logic is otherwise correct. The use of split() is explicitly required by the problem statement.\nPart A: 3 pts · Part B: 3 pts · Part C: 4 pts\nTotal: / 10\nAP Computer Science A · Answer Key — Teacher Copy\nCourseRecord — Answer Key\nFull solutions with inline explanations · Do not distribute to students\nPART A\ngetLastName()\n3 pts\npublic String getLastName()\n{\n // Find the index of the first comma\n // \"Johnson,Maria|...\" → commaIndex = 7\n int commaIndex = record.indexOf(\",\");\n\n // Substring from 0 up to (not including) the comma\n // \"Johnson,Maria|...\" → substring(0, 7) = \"Johnson\"\n return record.substring(0, commaIndex);\n}\nWhy it works: The last name is always the first token — before the first comma. indexOf(\",\") reliably finds that boundary regardless of name length. substring(0, commaIndex) extracts everything up to (but not including) the comma.\nPART B\ngetFormattedName()\n3 pts\npublic String getFormattedName()\n{\n // Locate both delimiters\n // record = \"Johnson,Maria|mjohnson@westlake.edu|88,92,76,95\"\n // ^7 ^13\n int commaIndex = record.indexOf(\",\");\n int pipeIndex = record.indexOf(\"|\");\n\n // Last name: before the comma\n String lastName = record.substring(0, commaIndex);\n\n // First name: between the comma and the first pipe\n String firstName = record.substring(commaIndex + 1, pipeIndex);\n\n // Return \"FirstName LastName\"\n return firstName + \" \" + lastName;\n}\nWhy it works: Two calls to indexOf establish three boundaries: [0, comma) = last name, (comma, pipe) = first name. Adding 1 to commaIndex skips the comma character itself. Concatenating in firstName + \" \" + lastName order produces the required output.\nPART C\ngetAverageScore()\n4 pts\npublic double getAverageScore()\n{\n // ── Step 1: Isolate the scores section ──────────────\n // Strip the name section first → \"mjohnson@westlake.edu|88,92,76,95\"\n String afterName = record.substring(record.indexOf(\"|\") + 1);\n\n // Strip the email section → \"88,92,76,95\"\n String scoresSection = afterName.substring(afterName.indexOf(\"|\") + 1);\n\n // ── Step 2: Split on comma → {\"88\",\"92\",\"76\",\"95\"} ──\n String[] scores = scoresSection.split(\",\");\n\n // ── Step 3: Accumulate sum ──────────────────────────\n double sum = 0;\n for (String s : scores)\n {\n sum += Integer.parseInt(s);\n }\n\n // ── Step 4: Return average ──────────────────────────\n // Dividing double by int → double result (no casting needed)\n return sum / scores.length;\n}\nWhy it works: Chaining two substring/indexOf calls peels off the first and second sections, leaving only the scores. split(\",\") turns \"88,92,76,95\" into a four-element array. Since sum is declared as double, dividing by the int scores.length automatically produces a double result — no cast needed.\n\nAlternate acceptable approach for isolating scores:\nStudents may also declare a second pipe index explicitly:\nint pipe1 = record.indexOf(\"|\");\nint pipe2 = record.indexOf(\"|\", pipe1 + 1); (two-arg indexOf — not on QR but acceptable)\nString scoresSection = record.substring(pipe2 + 1);\nOUTPUT\nExpected Console Output\n=== Part A: getLastName() ===\nr1 → Expected: Johnson | Actual: Johnson\nr2 → Expected: Smith | Actual: Smith\nr3 → Expected: De La Cruz | Actual: De La Cruz\n\n=== Part B: getFormattedName() ===\nr1 → Expected: Maria Johnson | Actual: Maria Johnson\nr2 → Expected: Alex Smith | Actual: Alex Smith\nr3 → Expected: Sam De La Cruz | Actual: Sam De La Cruz\n\n=== Part C: getAverageScore() ===\nr1 → Expected: 87.75 | Actual: 87.75\nr2 → Expected: 82.75 | Actual: 82.75\nr3 → Expected: 96.25 | Actual: 96.25\nPart A: 3 pts · Part B: 3 pts · Part C: 4 pts\nTotal: 10 pts",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "Radix Sort (Practice/Prep assignment)",
"prompt": "Follow along if you wish...\nStarter code:\n```java\nimport java.util.ArrayList;\npublic class radixSortDemo{\n public static void main(String[] args){\n int[] list = {123,234,134,156, 237, 231, 139, 313};\n viewArray(list);\n radixSort(list);\n viewArray(list);\n }\n public static void viewArray(int[] list){\n for(int temp : list){\n System.out.print(temp + \" \");\n }\n System.out.println();\n }\n public static void radixSort(int[] list){\n ArrayList<Integer>[] buckets = new ArrayList[10];\n for(int i = 0; i < buckets.length; i++){\n buckets[i] = new ArrayList<Integer>();\n }\n \n //Do this 3 times (starting with 3 digit numbers)\n\n \t//dump list in the buckets by digit\n \n \n \t//put back in list from buckets\n\n }\n }\n}\n```",
"rubric": "5 points for a reasonable attempt\n//This is just place holder code...NOT a key\nimport java.util.ArrayList;\npublic class radixSortDemo{\n public static void main(String[] args){\n int[] list = {123,234,134,156, 237, 231, 139, 313};\n viewArray(list);\n radixSort(list);\n viewArray(list);\n }\n public static void viewArray(int[] list){\n for(int temp : list){\n System.out.print(temp + \" \");\n }\n System.out.println();\n }\n public static void radixSort(int[] list){\n ArrayList<Integer>[] buckets = new ArrayList[10];\n for(int i = 0; i < buckets.length; i++){\n buckets[i] = new ArrayList<Integer>();\n }\n \n //Do this 3 times (starting with 3 digit numbers)\n for(int digit = 0; digit < 3; digit++){\n \tint place = (int)Math.pow(10,digit);\n System.out.println(place);\n \t//dump list in the buckets by digit\n \tfor(int temp: list){\n int index = (temp % (10*place)) / place;\n buckets[index].add(temp);\n } \n \n \t//put back in list from buckets\n int i = 0;\n for(int bucketNumber = 0; bucketNumber < 10; bucketNumber++){\n while(!buckets[bucketNumber].isEmpty()){\n list[i] = buckets[bucketNumber].remove(0);\n i++;\n }\n }\n viewArray(list);\n }\n }\n}",
"max_submissions": null,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Q1: TemperatureLog — Methods & Control Structures",
"prompt": "# AP Computer Science A — Free Response Question 1\n## TemperatureLog — Methods & Control Structures\n**Question 1 Style | Methods, if/else, Loops | 10 points total**\n\n---\n\n## Background\n\nA weather app records daily high temperatures (in degrees Fahrenheit) as an array of integers.\nThe `TemperatureLog` class stores one such array and provides methods to categorize and analyze the readings.\n\nEach temperature is classified into one of four categories:\n\n| Temperature (°F) | Category |\n|------------------|----------|\n| Less than 32 | `\"Cold\"` |\n| 32 up to (not including) 60 | `\"Cool\"` |\n| 60 up to (not including) 85 | `\"Warm\"` |\n| 85 or above | `\"Hot\"` |\n\nYou may assume `temps` contains at least one element and all values are valid integers.\n\n---\n\n## Starter Code\n\n```java\npublic class TemperatureLog\n{\n private int[] temps; // daily high temperatures in °F\n\n public TemperatureLog(int[] temps)\n {\n this.temps = temps;\n }\n\n // ── PART A ──────────────────────────────────────\n // Returns the category for a single temperature.\n public String getCategory(int temp)\n {\n // YOUR CODE HERE\n\n }\n\n // ── PART B ──────────────────────────────────────\n // Returns the count of readings matching the given category.\n // REQUIRED: must call getCategory in your solution.\n public int countCategory(String category)\n {\n // YOUR CODE HERE\n\n }\n\n // ── PART C ──────────────────────────────────────\n // Returns the length of the longest consecutive run of readings\n // whose category equals the given category. Returns 0 if none match.\n public int getLongestStreak(String category)\n {\n // YOUR CODE HERE\n\n }\n\n // ── TEST MAIN (do not modify) ─────────────────────\n public static void main(String[] args)\n {\n int[] denver = {28, 15, 31, 42, 55, 62, 68, 71, 65, 58, 45, 32};\n int[] phoenix = {65, 68, 72, 78, 85, 90, 88, 85, 79, 74, 70, 67};\n int[] seattle = {38, 40, 35, 28, 25, 30, 33, 37, 42, 44, 41, 36};\n\n TemperatureLog d = new TemperatureLog(denver);\n TemperatureLog p = new TemperatureLog(phoenix);\n TemperatureLog s = new TemperatureLog(seattle);\n\n System.out.println(\"=== Part A: getCategory() ===\");\n System.out.println(\"28°F → Expected: Cold | Actual: \" + d.getCategory(28));\n System.out.println(\"32°F → Expected: Cool | Actual: \" + d.getCategory(32));\n System.out.println(\"68°F → Expected: Warm | Actual: \" + d.getCategory(68));\n System.out.println(\"90°F → Expected: Hot | Actual: \" + p.getCategory(90));\n\n System.out.println(\"\n=== Part B: countCategory() ===\");\n System.out.println(\"denver Cold → Expected: 3 | Actual: \" + d.countCategory(\"Cold\"));\n System.out.println(\"denver Warm → Expected: 4 | Actual: \" + d.countCategory(\"Warm\"));\n System.out.println(\"phoenix Hot → Expected: 4 | Actual: \" + p.countCategory(\"Hot\"));\n System.out.println(\"seattle Cool → Expected: 9 | Actual: \" + s.countCategory(\"Cool\"));\n\n System.out.println(\"\n=== Part C: getLongestStreak() ===\");\n System.out.println(\"denver Cold streak → Expected: 3 | Actual: \" + d.getLongestStreak(\"Cold\"));\n System.out.println(\"denver Warm streak → Expected: 4 | Actual: \" + d.getLongestStreak(\"Warm\"));\n System.out.println(\"seattle Cool streak → Expected: 6 | Actual: \" + s.getLongestStreak(\"Cool\"));\n System.out.println(\"phoenix Hot streak → Expected: 4 | Actual: \" + p.getLongestStreak(\"Hot\"));\n }\n}\n```\n\n---\n\n## Part A — getCategory(int temp) *(3 points)*\n\nWrite the `getCategory` method. Given a single temperature value, return the appropriate category String from the table above.\n\n**Examples:**\n\n| temp | getCategory(temp) returns |\n|------|--------------------------|\n| 28 | `\"Cold\"` |\n| 32 | `\"Cool\"` |\n| 68 | `\"Warm\"` |\n| 90 | `\"Hot\"` |\n\n---\n\n## Part B — countCategory(String category) *(3 points)*\n\nWrite the `countCategory` method. Return the number of readings in `temps` whose category matches the given `category` string.\n\n> **Required:** You **must** call `getCategory` in your solution. A solution that does not call `getCategory` will receive 0 points for Part B, even if the output is correct.\n\n**Examples** (using `denver = {28, 15, 31, 42, 55, 62, 68, 71, 65, 58, 45, 32}`):\n\n| category | countCategory returns |\n|----------|-----------------------|\n| `Cold` | 3 |\n| `Cool` | 5 |\n| `Warm` | 4 |\n| `Hot` | 0 |\n\n---\n\n## Part C — getLongestStreak(String category) *(4 points)*\n\nWrite the `getLongestStreak` method. Return the length of the **longest consecutive run** of readings whose category matches `category`. Return 0 if no reading matches.\n\n**Examples:**\n\n| temps array | category | getLongestStreak returns |\n|-------------|----------|--------------------------|\n| {28,15,31,42,55,62,68,71,65,58,45,32} | `Cold` | 3 |\n| {28,15,31,42,55,62,68,71,65,58,45,32} | `Warm` | 4 |\n| {38,40,35,28,25,30,33,37,42,44,41,36} | `Cool` | 6 |\n| {65,68,72,78,85,90,88,85,79,74,70,67} | `Hot` | 4 |\n",
"rubric": "AP Computer Science A · Scoring Rubric — Teacher Copy\nTemperatureLog — Methods & Control Structures\n10 points total · Do not share with students before grading\n\nPART A\ngetCategory() — 3 points\n1 Uses an if/else if/else chain with at least three distinct conditions to distinguish all four categories.\n1 All four boundary conditions are correct: < 32 for Cold, < 60 for Cool, < 85 for Warm, >= 85 for Hot. All four must be correct.\n1 Returns the correct String literal for every case with exact spelling/capitalization (Cold, Cool, Warm, Hot).\nCommon errors: Off-by-one at boundaries (e.g., <= 32 instead of < 32). Wrong capitalization (cold). Missing the final else/return causes compile error.\n\nPART B\ncountCategory() — 3 points\n1 Declares and initializes an integer counter to 0 before the loop.\n1 Correctly traverses ALL elements of temps using a for loop or enhanced for.\n1 Calls getCategory on each element and compares with .equals() (not ==). Increments counter on match. Returns counter. This point is forfeited if getCategory is not called.\nCommon errors: Using == to compare Strings. Not calling getCategory and re-implementing the condition inline. Returning inside the loop.\nPENALTY: No call to getCategory = 0 points for Part B.\n\nPART C\ngetLongestStreak() — 4 points\n1 Declares maxStreak = 0 and currentStreak = 0 before the loop.\n1 Traverses all elements; increments currentStreak on category match, resets to 0 on mismatch.\n1 Updates maxStreak correctly inside the loop when currentStreak exceeds it.\n1 Returns maxStreak after loop completes. Returns 0 correctly when no element matches.\nCommon errors: Forgetting to reset currentStreak on mismatch. Updating maxStreak only after loop ends. Returning currentStreak instead of maxStreak.\n\nSAMPLE ANSWER:\n// Part A\npublic String getCategory(int temp) {\n if (temp < 32) return Cold;\n else if (temp < 60) return Cool;\n else if (temp < 85) return Warm;\n else return Hot;\n}\n// Part B\npublic int countCategory(String category) {\n int count = 0;\n for (int t : temps) {\n if (getCategory(t).equals(category)) count++;\n }\n return count;\n}\n// Part C\npublic int getLongestStreak(String category) {\n int maxStreak = 0, currentStreak = 0;\n for (int t : temps) {\n if (getCategory(t).equals(category)) {\n currentStreak++;\n if (currentStreak > maxStreak) maxStreak = currentStreak;\n } else {\n currentStreak = 0;\n }\n }\n return maxStreak;\n}\n",
"max_submissions": 3,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Q3: QuizTracker — Array/ArrayList",
"prompt": "## Free Response Question 3 — QuizTracker\n\nThis question involves a class that stores a list of student quiz scores. You will write **two methods** for the `QuizTracker` class.\n\n**Directions:** Write the code for each method. Your program must work correctly in all cases. Assume all necessary Java classes have been imported.\n\n---\n\n### The QuizTracker Class\n\n```java\npublic class QuizTracker {\n\n private ArrayList<Integer> scores;\n\n // Constructor - creates an empty list of scores\n public QuizTracker() {\n scores = new ArrayList<Integer>();\n }\n\n // Adds a score to the list\n public void addScore(int score) {\n scores.add(score);\n }\n\n // Returns the number of scores in the list\n public int getSize() {\n return scores.size();\n }\n\n // Part (a) - you will write this method\n public double getAverage() {\n /* to be implemented */\n }\n\n // Part (b) - you will write this method\n public int countAboveAverage() {\n /* to be implemented */\n }\n\n}\n```\n\n---\n\n### Part (a) — `getAverage` *(4 points)*\n\nWrite the `getAverage` method, which calculates and returns the **average** of all scores in `scores` as a `double`. If the list is empty, return `0.0`.\n\n---\n\n### Part (b) — `countAboveAverage` *(5 points)*\n\nWrite the `countAboveAverage` method, which returns the number of scores in `scores` that are **strictly greater than** the average.\n\n> **Requirement:** You must call `getAverage` as part of your solution.\n\n#### Examples\n\n| scores list | `getAverage()` | `countAboveAverage()` |\n|---|---|---|\n| `[70, 80, 90, 100]` | `85.0` | `2` (90 and 100 are strictly > 85.0) |\n| `[60, 60, 60, 60]` | `60.0` | `0` (no score strictly > 60.0) |\n| `[55, 72, 88]` | `71.666...` | `1` (only 88 is strictly > the average) |\n\n---\n\n**Submit your complete `QuizTracker` class including both methods.**",
"rubric": "## Scoring Rubric — QuizTracker (9 points total)\n\n### Part (a) — getAverage (4 points)\n\n| Criteria | Points |\n|---|---|\n| Initializes a sum variable to 0 or 0.0 | 1 |\n| Traverses all elements of scores using a loop (for or for-each) | 1 |\n| Accumulates the sum of all elements correctly | 1 |\n| Returns sum divided by size as a double AND handles empty list (returns 0.0) — must cast or use double arithmetic; must guard against divide-by-zero | 1 |\n\n### Part (b) — countAboveAverage (5 points)\n\n| Criteria | Points |\n|---|---|\n| Calls getAverage() and stores or uses the result (must use the method, not recompute manually) | 1 |\n| Initializes a counter variable to 0 | 1 |\n| Traverses all elements of scores using a loop (for or for-each) | 1 |\n| Compares each element strictly greater than the average (must use >, not >=) | 1 |\n| Returns the correct count | 1 |\n\n### General Notes\n- Carry-through credit: If a student makes an error in part (a) but uses that result consistently in part (b), they may still earn points in part (b).\n- Minor syntax errors (missing semicolons, minor spelling) are not penalized if intent is clear.\n- Students may not earn the traversal point if the loop does not visit all elements (e.g., off-by-one errors).\n\n### Example Solution (for grading reference only — do NOT show to students)\n\n**Part (a):**\n```java\npublic double getAverage() {\n if (scores.size() == 0) {\n return 0.0;\n }\n double sum = 0;\n for (int score : scores) {\n sum += score;\n }\n return sum / scores.size();\n}\n```\n\n**Part (b):**\n```java\npublic int countAboveAverage() {\n double avg = getAverage();\n int count = 0;\n for (int score : scores) {\n if (score > avg) {\n count++;\n }\n }\n return count;\n}\n```",
"max_submissions": null,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Q3: SongLibrary — Array/ArrayList",
"prompt": "## Free Response Question 3 — SongLibrary\n\nThis question involves a class that manages a music library using **two parallel ArrayLists**. You will write **three methods** for the `SongLibrary` class.\n\n**Directions:** Write the code for each method. Your program must work correctly in all cases, including edge cases. Assume all necessary Java classes have been imported.\n\n---\n\n### The SongLibrary Class\n\nThe class uses two parallel ArrayLists: the title at index `i` in `titles` corresponds to the play count at index `i` in `playCounts`.\n\n```java\npublic class SongLibrary {\n\n private ArrayList<String> titles;\n private ArrayList<Integer> playCounts;\n\n // Constructor - creates an empty library\n public SongLibrary() {\n titles = new ArrayList<String>();\n playCounts = new ArrayList<Integer>();\n }\n\n // Adds a song with the given title and play count\n public void addSong(String title, int count) {\n titles.add(title);\n playCounts.add(count);\n }\n\n // Returns the number of songs in the library\n public int getSize() { return titles.size(); }\n\n // Part (a) - you will write this method\n public double getAveragePlayCount() {\n /* to be implemented */\n }\n\n // Part (b) - you will write this method\n public String getMostPopular() {\n /* to be implemented */\n }\n\n // Part (c) - you will write this method\n public int removeBelowAverage() {\n /* to be implemented */\n }\n\n}\n```\n\n---\n\n### Part (a) — `getAveragePlayCount` *(3 points)*\n\nWrite the `getAveragePlayCount` method, which computes and returns the **average** of all values in `playCounts` as a `double`. If the library is empty, return `0.0`.\n\n| titles | playCounts | `getAveragePlayCount()` returns |\n|---|---|---|\n| `[\"Song A\", \"Song B\", \"Song C\"]` | `[10, 20, 30]` | `20.0` |\n| `[\"Song A\", \"Song B\"]` | `[5, 7]` | `6.0` |\n| (empty) | (empty) | `0.0` |\n\n---\n\n### Part (b) — `getMostPopular` *(3 points)*\n\nWrite the `getMostPopular` method, which returns the **title** of the song with the highest play count. You may assume the library has at least one song. If multiple songs share the highest play count, return the **first** one found.\n\n| titles | playCounts | `getMostPopular()` returns |\n|---|---|---|\n| `[\"Alpha\", \"Beta\", \"Gamma\"]` | `[15, 42, 28]` | `\"Beta\"` |\n| `[\"X\", \"Y\", \"Z\"]` | `[9, 9, 4]` | `\"X\"` *(first tie wins)* |\n| `[\"Only\"]` | `[0]` | `\"Only\"` |\n\n---\n\n### Part (c) — `removeBelowAverage` *(4 points)*\n\nWrite the `removeBelowAverage` method, which removes every song whose play count is **strictly less than** the average play count. When a song is removed, both its title **and** its play count must be removed from their respective lists. The method returns the **number of songs removed**.\n\n> **Requirement:** You must call `getAveragePlayCount()` as part of your solution.\n\n| playCounts before | Average | playCounts after | Returns |\n|---|---|---|---|\n| `[10, 50, 20, 80]` | `40.0` | `[50, 80]` | `2` |\n| `[25, 25, 25]` | `25.0` | `[25, 25, 25]` *(nothing strictly less)* | `0` |\n| `[3, 97]` | `50.0` | `[97]` | `1` |\n\n*Note for the first example: average is 40.0, so songs with counts 10 and 20 are removed.*\n\n---\n\n**Submit your complete `SongLibrary` class including all three methods.**",
"rubric": "## Scoring Rubric — SongLibrary (10 points total)\n\n### Part (a) — getAveragePlayCount (3 points)\n\n| Criteria | Points |\n|---|---|\n| Attempts to iterate over `playCounts` and accumulate a sum | 1 |\n| Sum and loop are correct (all elements included, no off-by-one) | 1 |\n| Returns result as a `double` (not integer division) AND returns `0.0` for empty list | 1 |\n\n*Partial credit: integer division with no cast loses point 3 only. Forgetting the empty-list guard loses point 3 only.*\n\n---\n\n### Part (b) — getMostPopular (3 points)\n\n| Criteria | Points |\n|---|---|\n| Initializes a tracker for the maximum value (or index) before the loop | 1 |\n| Correctly iterates and updates the tracker when a strictly greater value is found | 1 |\n| Returns the **title** at the winning index (not the play count itself) | 1 |\n\n*Partial credit: returning the count instead of the title loses point 3 only. Using `>=` instead of `>` (breaking tie rule) loses point 3 only.*\n\n---\n\n### Part (c) — removeBelowAverage (4 points)\n\n| Criteria | Points |\n|---|---|\n| Calls `getAveragePlayCount()` and stores the result **before** the removal loop | 1 |\n| Sets up a loop that traverses the list with a viable strategy | 1 |\n| Correctly removes from **both** `titles` and `playCounts` at the same index, with correct index handling (e.g., traverses backwards, or decrements `i` after removal) | 1 |\n| Correctly returns the number of songs removed | 1 |\n\n*Partial credit: removing from only one list loses point 3 only. Calling `getAveragePlayCount()` inside the loop instead of before it loses point 1, but can still earn points 2–4 if the rest is correct. Not returning the count loses point 4 only.*\n\n---\n\n### General Notes\n- Carry-through credit: If a student's `getAveragePlayCount()` is wrong but they use that result consistently in part (c), they may still earn points in part (c).\n- Minor syntax errors (missing semicolons, minor capitalization) are not penalized if intent is clear.\n- The key pitfall in part (c) is index shifting during ArrayList removal — award point 3 only if both lists are modified **and** the index is managed correctly.\n\n---\n\n### Example Solution (for grading reference only — do NOT show to students)\n\n**Part (a):**\n```java\npublic double getAveragePlayCount() {\n if (playCounts.size() == 0) {\n return 0.0;\n }\n double sum = 0;\n for (int count : playCounts) {\n sum += count;\n }\n return sum / playCounts.size();\n}\n```\n\n**Part (b):**\n```java\npublic String getMostPopular() {\n int maxIndex = 0;\n for (int i = 1; i < playCounts.size(); i++) {\n if (playCounts.get(i) > playCounts.get(maxIndex)) {\n maxIndex = i;\n }\n }\n return titles.get(maxIndex);\n}\n```\n\n**Part (c):**\n```java\npublic int removeBelowAverage() {\n double avg = getAveragePlayCount();\n int removed = 0;\n for (int i = playCounts.size() - 1; i >= 0; i--) {\n if (playCounts.get(i) < avg) {\n titles.remove(i);\n playCounts.remove(i);\n removed++;\n }\n }\n return removed;\n}\n```",
"max_submissions": null,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "FRQ Q3 — WordList (Arrays & ArrayLists)",
"prompt": "AP CS A Free Response Question 3 — WordList\n\nThis question involves a class that manages a list of words stored in an ArrayList<String>. Complete all five methods listed below.\n\nUse this starter code (include the main() — your output must match the expected results):\n\n```java\nimport java.util.ArrayList;\n\npublic class WordList {\n\n private ArrayList<String> words;\n\n public WordList(ArrayList<String> w) {\n words = w;\n }\n\n /** Returns the words list (provided — do not rewrite). */\n public ArrayList<String> getWords() {\n return words;\n }\n\n /** Part (a)\n * Returns the number of words whose length is strictly greater than minLen.\n * Precondition: minLen >= 0\n */\n public int countLongerThan(int minLen) {\n // YOUR CODE HERE\n }\n\n /** Part (b)\n * Returns a NEW ArrayList containing all words that begin with letter,\n * in the order they appear in words. Does NOT modify the original list.\n * Returns an empty list if no words match.\n */\n public ArrayList<String> getWordsStartingWith(char letter) {\n // YOUR CODE HERE\n }\n\n /** Part (c)\n * Removes from words every word that contains target as a substring.\n * Modifies words directly. Words not containing target stay in original order.\n * Precondition: target.length() >= 1\n * Hint: use s.indexOf(target) >= 0 OR s.contains(target)\n */\n public void removeContaining(String target) {\n // YOUR CODE HERE\n }\n\n /** Part (d)\n * Returns the word that comes first alphabetically among all words.\n * Precondition: words.size() >= 1\n * Hint: a.compareTo(b) returns negative if a comes before b alphabetically.\n */\n public String getAlphaFirst() {\n // YOUR CODE HERE\n }\n\n /** Part (e)\n * Removes all later duplicate occurrences of any word.\n * Keeps the FIRST occurrence; removes all subsequent copies.\n * Modifies words directly. Relative order of first occurrences is preserved.\n * Remember: use .equals() to compare Strings, never ==.\n */\n public void removeDuplicates() {\n // YOUR CODE HERE\n }\n\n public static void main(String[] args) {\n // === Part (a): countLongerThan ===\n ArrayList<String> list1 = new ArrayList<>();\n list1.add(\"cat\"); list1.add(\"elephant\"); list1.add(\"dog\");\n list1.add(\"hippopotamus\"); list1.add(\"ox\");\n WordList wl1 = new WordList(list1);\n System.out.println(\"=== Part (a) ===\");\n System.out.println(wl1.countLongerThan(3)); // Expected: 2\n System.out.println(wl1.countLongerThan(2)); // Expected: 4\n System.out.println(wl1.countLongerThan(11)); // Expected: 1\n\n // === Part (b): getWordsStartingWith ===\n System.out.println(\"=== Part (b) ===\");\n System.out.println(wl1.getWordsStartingWith('e')); // Expected: [elephant]\n System.out.println(wl1.getWordsStartingWith('z')); // Expected: []\n System.out.println(wl1.getWordsStartingWith('c')); // Expected: [cat]\n\n // === Part (c): removeContaining ===\n ArrayList<String> list2 = new ArrayList<>();\n list2.add(\"canal\"); list2.add(\"ban\"); list2.add(\"bandana\");\n list2.add(\"stone\"); list2.add(\"can\");\n WordList wl2 = new WordList(list2);\n wl2.removeContaining(\"an\");\n System.out.println(\"=== Part (c) ===\");\n System.out.println(wl2.getWords()); // Expected: [stone]\n\n ArrayList<String> list2b = new ArrayList<>();\n list2b.add(\"apple\"); list2b.add(\"pineapple\");\n list2b.add(\"pine\"); list2b.add(\"mango\");\n WordList wl2b = new WordList(list2b);\n wl2b.removeContaining(\"apple\");\n System.out.println(wl2b.getWords()); // Expected: [pine, mango]\n\n // === Part (d): getAlphaFirst ===\n ArrayList<String> list3 = new ArrayList<>();\n list3.add(\"mango\"); list3.add(\"apple\"); list3.add(\"cherry\"); list3.add(\"avocado\");\n WordList wl3 = new WordList(list3);\n System.out.println(\"=== Part (d) ===\");\n System.out.println(wl3.getAlphaFirst()); // Expected: apple\n\n ArrayList<String> list3b = new ArrayList<>();\n list3b.add(\"tiger\"); list3b.add(\"bear\"); list3b.add(\"lion\");\n WordList wl3b = new WordList(list3b);\n System.out.println(wl3b.getAlphaFirst()); // Expected: bear\n\n // === Part (e): removeDuplicates ===\n ArrayList<String> list4 = new ArrayList<>();\n list4.add(\"rose\"); list4.add(\"lily\"); list4.add(\"rose\");\n list4.add(\"daisy\"); list4.add(\"lily\"); list4.add(\"rose\");\n WordList wl4 = new WordList(list4);\n wl4.removeDuplicates();\n System.out.println(\"=== Part (e) ===\");\n System.out.println(wl4.getWords()); // Expected: [rose, lily, daisy]\n\n ArrayList<String> list4b = new ArrayList<>();\n list4b.add(\"a\"); list4b.add(\"a\"); list4b.add(\"a\");\n WordList wl4b = new WordList(list4b);\n wl4b.removeDuplicates();\n System.out.println(wl4b.getWords()); // Expected: [a]\n }\n}\n```",
"rubric": "WordList FRQ Q3 Rubric — 15 points total\n\nPart (a): countLongerThan — 2 points\n 1 point: Correct accumulator pattern — counter initialized before loop, return statement is AFTER the loop (not inside it)\n 1 point: Correct condition uses word.length() > minLen (strictly greater than, NOT >= minLen)\n\nPart (b): getWordsStartingWith — 3 points\n 1 point: Creates a new ArrayList<String> result before the loop and returns it after the loop\n 1 point: Correct condition checks first character — uses charAt(0) == letter or substring(0,1).equals(String.valueOf(letter)) or similar valid approach\n 1 point: Does NOT modify the original words list — reads from words using for-each or indexed loop without removing/adding; adds matching words to the new result list\n\nPart (c): removeContaining — 4 points\n 1 point: Uses a correct removal-safe pattern — either a while loop with a manual index variable, or a backwards for loop (i from size()-1 down to 0)\n 1 point: Correctly detects substring using indexOf(target) >= 0 or contains(target) — NOT equals() or startsWith() alone\n 1 point: Index is only incremented when NOT removing — avoids skipping the element that shifts into the removed position\n 1 point: Modifies words directly in place (does not create and return a new list)\n\nPart (d): getAlphaFirst — 2 points\n 1 point: Seeds the running minimum correctly using words.get(0), NOT with an empty string \"\" or null (seeding with \"\" is wrong because \"\" sorts before any word)\n 1 point: Uses compareTo correctly — updates the running minimum when a word compares less than the current minimum; returns the correct alphabetically first word after the loop\n\nPart (e): removeDuplicates — 4 points\n 1 point: Uses a correct removal-safe iteration pattern (while loop with manual index, or backwards loop)\n 1 point: Correctly identifies a duplicate by comparing the current word against all EARLIER positions (indices 0 through i-1) using .equals() — does NOT use == for String comparison\n 1 point: Only removes and holds the index still when a duplicate is found; increments index when NOT removing\n 1 point: Result preserves the relative order of the FIRST occurrences — later copies removed, first copies kept",
"max_submissions": 3,
"is_visible": 0,
"tab_monitoring_enabled": 0
},
{
"title": "AP Q1: PlayerRank — Methods & Control Structures",
"prompt": "# AP Computer Science A — Free Response Question 1\n## PlayerRank — Methods and Control Structures\n**Question 1 Style | Methods, if/else, Loops, Math.random() | 9 points total**\n\n---\n\n## Background\n\nAn online multiplayer game awards and deducts *ranking points* after each match. A player who wins several matches in a row builds a **win streak** and earns bonus points while that streak is active. The `PlayerRank` class tracks a single player's current ranking points and win streak.\n\nRanking points change after each match according to these rules:\n\n| Match Result | Change to `rankPoints` | Change to `winStreak` |\n|---|---|---|\n| Win — `winStreak` is less than 3 before this match | Add 25 points | Increment by 1 |\n| Win — `winStreak` is 3 or more before this match | Add 40 points (25 base + 15 streak bonus) | Increment by 1 |\n| Loss (any) | Subtract 15 points | Reset to 0 |\n\nNote: `rankPoints` may become negative. You may assume `winStreak` is never negative.\n\n---\n\n## Starter Code\n\n```java\npublic class PlayerRank\n{\n private int rankPoints;\n private int winStreak;\n\n public PlayerRank(int startingPoints)\n {\n rankPoints = startingPoints;\n winStreak = 0;\n }\n\n // PART A\n // Updates rankPoints and winStreak based on match result.\n // won = true for a win, false for a loss.\n public void recordMatch(boolean won)\n {\n // YOUR CODE HERE\n\n }\n\n // PART B\n // Simulates matches games. For each game, if Math.random() < winRate\n // the player won; otherwise the player lost.\n // Must call recordMatch for every game.\n // Returns the total number of wins.\n public int countWins(int matches, double winRate)\n {\n // YOUR CODE HERE\n\n }\n\n public int getRankPoints() { return rankPoints; }\n public int getWinStreak() { return winStreak; }\n\n // TEST MAIN (do not modify)\n public static void main(String[] args)\n {\n System.out.println(\"=== Part A: recordMatch() ===\");\n PlayerRank p = new PlayerRank(1000);\n\n p.recordMatch(true);\n System.out.println(\"Win 1 points: \" + p.getRankPoints() + \" (expected 1025) streak: \" + p.getWinStreak() + \" (expected 1)\");\n\n p.recordMatch(true);\n System.out.println(\"Win 2 points: \" + p.getRankPoints() + \" (expected 1050) streak: \" + p.getWinStreak() + \" (expected 2)\");\n\n p.recordMatch(true);\n System.out.println(\"Win 3 points: \" + p.getRankPoints() + \" (expected 1075) streak: \" + p.getWinStreak() + \" (expected 3)\");\n\n p.recordMatch(true);\n System.out.println(\"Win 4 points: \" + p.getRankPoints() + \" (expected 1115) streak: \" + p.getWinStreak() + \" (expected 4)\");\n\n p.recordMatch(false);\n System.out.println(\"Loss points: \" + p.getRankPoints() + \" (expected 1100) streak: \" + p.getWinStreak() + \" (expected 0)\");\n\n System.out.println(\"\");\n System.out.println(\"=== Part B: countWins() ===\");\n\n PlayerRank p2 = new PlayerRank(500);\n int w1 = p2.countWins(10, 1.0);\n System.out.println(\"winRate=1.0, 10 games wins: \" + w1 + \" (expected 10)\");\n\n PlayerRank p3 = new PlayerRank(500);\n int w2 = p3.countWins(10, 0.0);\n System.out.println(\"winRate=0.0, 10 games wins: \" + w2 + \" (expected 0)\");\n\n PlayerRank p4 = new PlayerRank(500);\n int w3 = p4.countWins(0, 0.5);\n System.out.println(\"winRate=0.5, 0 games wins: \" + w3 + \" (expected 0)\");\n\n PlayerRank p5 = new PlayerRank(500);\n int w4 = p5.countWins(100, 0.5);\n System.out.println(\"winRate=0.5, 100 games wins: \" + w4 + \" (expected roughly 50)\");\n }\n}\n```\n\n---\n\n## Part A — recordMatch(boolean won) *(4 points)*\n\nWrite the `recordMatch` method. The parameter `won` is `true` if the player won and `false` if the player lost. Update `rankPoints` and `winStreak` according to the rules in the table above.\n\n**Trace** (starting from `new PlayerRank(1000)`):\n\n| Call # | won | rankPoints before | winStreak before | rankPoints after | winStreak after |\n|---|---|---|---|---|---|\n| 1st | true | 1000 | 0 | 1025 | 1 |\n| 2nd | true | 1025 | 1 | 1050 | 2 |\n| 3rd | true | 1050 | 2 | 1075 | 3 |\n| 4th | true | 1075 | 3 | 1115 | 4 |\n| 5th | false | 1115 | 4 | 1100 | 0 |\n\n---\n\n## Part B — countWins(int matches, double winRate) *(5 points)*\n\nWrite the `countWins` method. Simulate `matches` games. For each game, if `Math.random() < winRate` the player won; otherwise the player lost. Return the total number of wins.\n\n> **Required:** You **must** call `recordMatch` for every game — passing `true` for a win, `false` for a loss. A solution that does not call `recordMatch` will receive 0 points for Part B.\n\n**Deterministic boundary cases:**\n\n| matches | winRate | countWins returns |\n|---|---|---|\n| 10 | 1.0 | 10 (always wins) |\n| 10 | 0.0 | 0 (always loses) |\n| 0 | 0.5 | 0 (no games played) |\n\n---\n\n**Submit your complete `PlayerRank` class including both methods and the unchanged main.**",
"rubric": "AP Computer Science A - Scoring Rubric - Teacher Copy\nPlayerRank - Methods and Control Structures\n9 points total - Do not share with students before grading\n\nPART A\nrecordMatch() - 4 points\n1 Adds 25 to rankPoints on a win when winStreak < 3 before the match.\n1 Adds 40 total (not just 15) when winStreak >= 3 before the win (streak bonus case).\n1 Subtracts 15 from rankPoints on a loss and resets winStreak to 0.\n1 Increments winStreak by 1 on every win (both streak and non-streak wins).\n\nCommon errors: Using > 3 instead of >= 3. Adding only 15 instead of 40 on a streak win.\nForgetting to increment winStreak. Not resetting winStreak on a loss.\n\nPART B\ncountWins() - 5 points\n1 Loops exactly matches times (0 iterations when matches = 0).\n1 Correctly determines outcome: Math.random() < winRate means won.\n1 Calls recordMatch(true) on a win and recordMatch(false) on a loss every iteration.\n1 Tracks wins with an integer counter incremented only on a win.\n1 Returns the win count after all matches.\n\nPenalty: No call to recordMatch = 0 points for Part B.\n\nSAMPLE ANSWER:\npublic void recordMatch(boolean won) {\n if (won) {\n if (winStreak >= 3) {\n rankPoints += 40;\n } else {\n rankPoints += 25;\n }\n winStreak++;\n } else {\n rankPoints -= 15;\n winStreak = 0;\n }\n}\n\npublic int countWins(int matches, double winRate) {\n int wins = 0;\n for (int i = 0; i < matches; i++) {\n boolean won = Math.random() < winRate;\n recordMatch(won);\n if (won) wins++;\n }\n return wins;\n}",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Q3: RankingBoard — Array/ArrayList",
"prompt": "## Free Response Question 3 — RankingBoard\n\nThis question involves a class that stores a list of player ranking point totals using an `ArrayList<Integer>`. You will write **two methods** for the `RankingBoard` class.\n\n**Directions:** Write the complete method body for each part. Your solution must work correctly in all cases. Assume all necessary Java classes have been imported.\n\n---\n\n### The RankingBoard Class\n\n```java\nimport java.util.ArrayList;\n\npublic class RankingBoard\n{\n private ArrayList<Integer> rankPoints;\n\n public RankingBoard()\n {\n rankPoints = new ArrayList<Integer>();\n }\n\n public void addEntry(int points)\n {\n rankPoints.add(points);\n }\n\n public int getSize()\n {\n return rankPoints.size();\n }\n\n // Part (a) - you will write this method\n public int getTopScore()\n {\n /* to be implemented */\n }\n\n // Part (b) - you will write this method\n public int removeBelowCutoff(int cutoff)\n {\n /* to be implemented */\n }\n\n public static void main(String[] args)\n {\n System.out.println(\"=== Part A: getTopScore() ===\");\n\n RankingBoard b1 = new RankingBoard();\n for (int pts : new int[]{1250, 875, 500, 1100, 340, 950}) b1.addEntry(pts);\n System.out.println(\"Top score: \" + b1.getTopScore() + \" (expected 1250)\");\n\n RankingBoard b2 = new RankingBoard();\n System.out.println(\"Empty: \" + b2.getTopScore() + \" (expected 0)\");\n\n RankingBoard b3 = new RankingBoard();\n for (int pts : new int[]{600, 600, 600}) b3.addEntry(pts);\n System.out.println(\"All same: \" + b3.getTopScore() + \" (expected 600)\");\n\n System.out.println(\"\");\n System.out.println(\"=== Part B: removeBelowCutoff() ===\");\n\n RankingBoard b4 = new RankingBoard();\n for (int pts : new int[]{1250, 875, 500, 1100, 340, 950}) b4.addEntry(pts);\n int r1 = b4.removeBelowCutoff(900);\n System.out.println(\"cutoff=900 removed: \" + r1 + \" (expected 3) size after: \" + b4.getSize() + \" (expected 3)\");\n\n RankingBoard b5 = new RankingBoard();\n for (int pts : new int[]{1250, 875, 500, 1100, 340, 950}) b5.addEntry(pts);\n int r2 = b5.removeBelowCutoff(1000);\n System.out.println(\"cutoff=1000 removed: \" + r2 + \" (expected 4) size after: \" + b5.getSize() + \" (expected 2)\");\n\n RankingBoard b6 = new RankingBoard();\n for (int pts : new int[]{800, 800, 800}) b6.addEntry(pts);\n int r3 = b6.removeBelowCutoff(800);\n System.out.println(\"cutoff=800 removed: \" + r3 + \" (expected 0) size after: \" + b6.getSize() + \" (expected 3)\");\n\n RankingBoard b7 = new RankingBoard();\n for (int pts : new int[]{100, 200, 300}) b7.addEntry(pts);\n int r4 = b7.removeBelowCutoff(400);\n System.out.println(\"cutoff=400 removed: \" + r4 + \" (expected 3) size after: \" + b7.getSize() + \" (expected 0)\");\n }\n}\n```\n\n---\n\n### Part (a) — `getTopScore` *(4 points)*\n\nWrite the `getTopScore` method, which returns the highest value in `rankPoints`. If the list is empty, return `0`.\n\n| rankPoints list | getTopScore() returns |\n|---|---|\n| `[1250, 875, 500, 1100, 340, 950]` | `1250` |\n| `[800]` | `800` |\n| `[600, 600, 600]` | `600` |\n| `[]` (empty) | `0` |\n\n---\n\n### Part (b) — `removeBelowCutoff` *(5 points)*\n\nWrite the `removeBelowCutoff` method, which removes every entry from `rankPoints` whose value is **strictly less than** `cutoff`. The order of the remaining entries must be preserved. The method returns the number of entries removed.\n\n> **Note:** An entry equal to `cutoff` is **not** removed.\n\n| rankPoints (before) | cutoff | Returns | rankPoints (after) |\n|---|---|---|---|\n| `[1250, 875, 500, 1100, 340, 950]` | 900 | 3 | `[1250, 1100, 950]` |\n| `[1250, 875, 500, 1100, 340, 950]` | 1000 | 4 | `[1250, 1100]` |\n| `[800, 800, 800]` | 800 | 0 | `[800, 800, 800]` |\n| `[100, 200, 300]` | 400 | 3 | `[]` |\n\n---\n\n**Submit your complete `RankingBoard` class including both methods and the unchanged main.**",
"rubric": "AP Computer Science A - Scoring Rubric - Teacher Copy\nRankingBoard - Array/ArrayList\n9 points total - Do not share with students before grading\n\nPART A\ngetTopScore() - 4 points\n1 Returns 0 (not an exception) when the list is empty.\n1 Initializes a max variable to a sensible starting value before traversal.\n1 Correctly traverses all elements of the ArrayList.\n1 Returns the maximum value found.\n\nCommon errors: Failing to handle the empty list causes IndexOutOfBoundsException.\nReturning inside the loop before all elements are examined. Starting max at 0 may cause issues\nif all values are negative, though this is unlikely in this domain.\n\nPART B\nremoveBelowCutoff() - 5 points\n1 Initializes a count variable to 0 before iteration.\n1 Uses a correct traversal that avoids the index-drift bug (backward loop or index adjustment).\n1 Condition is strictly less than (<), not less than or equal (<=).\n1 Removes qualifying elements from the ArrayList using remove(index).\n1 Returns the total count of removed elements.\n\nCommon errors (major trap): Forward iteration with removal skips elements immediately after\na removed one. Only award traversal point if the approach is provably correct.\nUsing <= instead of < fails the boundary case where an entry equals cutoff exactly.\n\nSAMPLE ANSWER:\npublic int getTopScore() {\n if (rankPoints.isEmpty()) return 0;\n int max = rankPoints.get(0);\n for (int i = 1; i < rankPoints.size(); i++) {\n if (rankPoints.get(i) > max) max = rankPoints.get(i);\n }\n return max;\n}\n\npublic int removeBelowCutoff(int cutoff) {\n int count = 0;\n for (int i = rankPoints.size() - 1; i >= 0; i--) {\n if (rankPoints.get(i) < cutoff) {\n rankPoints.remove(i);\n count++;\n }\n }\n return count;\n}",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Q2: TrailHiker — Class Writing",
"prompt": "# AP Computer Science A — Free Response Question 2\n## TrailHiker — Class Writing\n**Question 2 Style | Class Design, Instance Variables, Constructor, Methods | 9 points total**\n\n---\n\n## Background\n\n*Summit Seekers* is a nonprofit organization that coordinates charity hikes across national parks. Volunteers select a trail, hike from the trailhead toward the summit, and collect pledge money from sponsors for every mile they complete. A volunteer who reaches or passes the summit milestone earns a special Summit designation in the organization's records.\n\nThe organization's app represents each volunteer's participation as a single `TrailHiker` object. **Each `TrailHiker` object represents exactly one hiker on exactly one trail.** A hiker's trail name and summit distance are fixed at construction time and do not change.\n\n---\n\n## Your Task\n\nWrite the **complete** `TrailHiker` class. You must:\n1. Declare all necessary **private** instance variables\n2. Write the **constructor**\n3. Write the **`recordHike`** method\n4. Write the **`toString`** method\n\n---\n\n## Starter Code\n\n```java\npublic class TrailHiker\n{\n // ── Declare your private instance variables here ──────────────────\n\n\n // ── Constructor ────────────────────────────────────────────────────\n // trailName: the name of the trail this hiker is on\n // summitMile: distance in miles to the summit (always a positive int)\n public TrailHiker(String trailName, int summitMile)\n {\n // YOUR CODE HERE\n }\n\n // ── recordHike ─────────────────────────────────────────────────────\n // Adds miles to this hiker's total. If the total now reaches or\n // exceeds summitMile for the first time, marks the summit as reached.\n // Once reached, summit status must never be reset to false.\n // You may assume miles is always a positive integer.\n public void recordHike(int miles)\n {\n // YOUR CODE HERE\n }\n\n // ── toString ───────────────────────────────────────────────────────\n // If summit reached: \"[trailName]: Summit reached! [milesHiked] mi total\"\n // Otherwise: \"[trailName]: [milesHiked] mi of [summitMile]\"\n public String toString()\n {\n // YOUR CODE HERE\n }\n\n // ── TEST MAIN (do not modify) ──────────────────────────────────────\n public static void main(String[] args)\n {\n TrailHiker t = new TrailHiker(\"Blue Ridge\", 15);\n\n System.out.println(t);\n System.out.println(\"Expected: Blue Ridge: 0 mi of 15\");\n\n t.recordHike(8);\n System.out.println(t);\n System.out.println(\"Expected: Blue Ridge: 8 mi of 15\");\n\n t.recordHike(7);\n System.out.println(t);\n System.out.println(\"Expected: Blue Ridge: Summit reached! 15 mi total\");\n\n t.recordHike(3);\n System.out.println(t);\n System.out.println(\"Expected: Blue Ridge: Summit reached! 18 mi total\");\n\n System.out.println(\"\");\n\n TrailHiker t2 = new TrailHiker(\"Appalachian\", 10);\n t2.recordHike(10);\n System.out.println(t2);\n System.out.println(\"Expected: Appalachian: Summit reached! 10 mi total\");\n\n TrailHiker t3 = new TrailHiker(\"Mount Olympus\", 20);\n t3.recordHike(5);\n t3.recordHike(6);\n System.out.println(t3);\n System.out.println(\"Expected: 11 mi total\");\n }\n}\n```\n\n---\n\n## Instance Variables\n\nThe `TrailHiker` class must maintain the following information. You are responsible for choosing appropriate variable names and types, and declaring them **private**.\n\n| Information to Store | Initial Value |\n|---|---|\n| The name of the trail this hiker is on | Constructor parameter `trailName` |\n| The distance in miles to the summit | Constructor parameter `summitMile` (positive int) |\n| Total miles this hiker has completed so far | `0` |\n| Whether this hiker has reached the summit | `false` |\n\n---\n\n## Method: recordHike(int miles)\n\nAdds `miles` to this hiker's total. You may assume `miles` is always a positive integer.\n\nAfter adding, if the hiker's total has **reached or exceeded** `summitMile` for the **first time**, mark the summit as reached. Once the summit is marked as reached, it must **never** be set back to `false`.\n\n---\n\n## Method: toString()\n\nReturns a `String` describing this hiker's current state:\n\n| Condition | Returned String |\n|---|---|\n| Summit reached | `\"[trailName]: Summit reached! [milesHiked] mi total\"` |\n| Summit not yet reached | `\"[trailName]: [milesHiked] mi of [summitMile]\"` |\n\n**Example trace** starting from `new TrailHiker(\"Blue Ridge\", 15)`:\n\n| Statement | toString() returns | Miles hiked | Summit? |\n|---|---|---|---|\n| *(just constructed)* | `\"Blue Ridge: 0 mi of 15\"` | 0 | false |\n| `recordHike(8)` | — | 8 | false |\n| *after recordHike(8)* | `\"Blue Ridge: 8 mi of 15\"` | 8 | false |\n| `recordHike(7)` | — | 15 | true |\n| *after recordHike(7)* | `\"Blue Ridge: Summit reached! 15 mi total\"` | 15 | true |\n| `recordHike(3)` | — | 18 | true |\n| *after recordHike(3)* | `\"Blue Ridge: Summit reached! 18 mi total\"` | 18 | true |\n\n---\n\n**Submit your complete `TrailHiker` class including all instance variables, the constructor, both methods, and the unchanged main.**",
"rubric": "AP Computer Science A - Scoring Rubric - Teacher Copy\nTrailHiker - Class Writing\n9 points total - Do not share with students before grading\n\nPOINT 1 - Private instance variables\nAt least 4 private instance variables declared with appropriate types:\n String for trail name, int for summitMile, int for milesHiked, boolean for reachedSummit.\nAll instance variables used by the class must be private (not public, not static).\nDeduct this point if any instance variable is not declared private.\n\nPOINT 2 - Constructor initialization\nConstructor correctly initializes all instance variables:\n trailName and summitMile from parameters; milesHiked = 0; reachedSummit = false.\nAward this point if all 4 are initialized correctly.\n\nPOINT 3 - recordHike method header\npublic void recordHike(int miles) — correct return type, parameter type, and method name.\nMust be public, void, take exactly one int parameter.\n\nPOINT 4 - Adds miles to running total\nmiles is added to the milesHiked instance variable (or equivalent accumulator).\nDeduct if miles is stored directly without accumulating.\n\nPOINT 5 - Correct summit threshold check\nUses >= (not >) to compare milesHiked to summitMile after adding.\nBoth milesHiked >= summitMile and summitMile <= milesHiked are acceptable.\n\nPOINT 6 - Sets summit flag; never resets it\nreachedSummit is set to true when the threshold is first met.\nThe flag is NEVER set back to false — it must be inside a conditional that checks\nthe current summit status (e.g., if (!reachedSummit) or if (reachedSummit == false)).\nDeduct only if the flag could be explicitly reset to false by a subsequent call to recordHike.\n\nPOINT 7 - toString method header\npublic String toString() — no parameters, returns String, correct name and visibility.\n\nPOINT 8 - Summit-reached return string\nReturns the exact format \"[trailName]: Summit reached! [milesHiked] mi total\"\nwhen reachedSummit is true. String must use the actual values of the instance variables,\nnot hardcoded strings.\n\nPOINT 9 - Not-yet-reached return string\nReturns the exact format \"[trailName]: [milesHiked] mi of [summitMile]\"\nwhen reachedSummit is false. Must reflect live values of the instance variables.\n\n---\n\nCOMMON ERRORS:\n- Using > instead of >= in the threshold check (off-by-one: hiker who hikes exactly to the summit is not credited)\n- Resetting reachedSummit to false when milesHiked < summitMile (loses point 6) - only deduct if student explicitly resets to false\n- Missing the conditional guard on reachedSummit — overwriting true with false\n- Concatenating wrong variable (e.g., summitMile instead of milesHiked in summit string)\n- Declaring instance variables as public or static (loses point 1)\n\nSAMPLE ANSWER:\npublic class TrailHiker\n{\n private String trailName;\n private int summitMile;\n private int milesHiked;\n private boolean reachedSummit;\n\n public TrailHiker(String trailName, int summitMile)\n {\n this.trailName = trailName;\n this.summitMile = summitMile;\n milesHiked = 0;\n reachedSummit = false;\n }\n\n public void recordHike(int miles)\n {\n milesHiked += miles;\n if (!reachedSummit && milesHiked >= summitMile)\n {\n reachedSummit = true;\n }\n }\n\n public String toString()\n {\n if (reachedSummit)\n return trailName + \": Summit reached! \" + milesHiked + \" mi total\";\n else\n return trailName + \": \" + milesHiked + \" mi of \" + summitMile;\n }\n}",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Q1: StudyStreak — Methods & Control Structures (REASSESS)",
"prompt": "# AP Computer Science A — Free Response Question 1 (Reassessment)\n## StudyStreak — Methods and Control Structures\n**Question 1 Style | Methods, if/else, Loops, Math.random() | 9 points total**\n\n---\n\n## Background\n\nA study app rewards students for logging daily practice sessions. Each day a student logs, they earn points. A student who studies on **four or more consecutive days** builds a day streak and earns a bonus on every subsequent day while the streak holds. Missing a single day breaks the streak and deducts points.\n\nThe `StudyStreak` class tracks one student's accumulated points and current consecutive-day streak.\n\n| Day Result | Change to `points` | Change to `dayStreak` |\n|---|---|---|\n| Studied — `dayStreak` is less than 4 before this day | Add 100 points | Increment by 1 |\n| Studied — `dayStreak` is 4 or more before this day | Add 150 points (100 base + 50 streak bonus) | Increment by 1 |\n| Missed (did not study) | Subtract 30 points | Reset to 0 |\n\nNote: `points` may become negative. You may assume `dayStreak` is never negative.\n\n---\n\n## Starter Code\n\n```java\npublic class StudyStreak\n{\n private int points;\n private int dayStreak;\n\n public StudyStreak(int startingPoints)\n {\n points = startingPoints;\n dayStreak = 0;\n }\n\n // PART A\n // Updates points and dayStreak based on whether the student studied.\n // studied = true means they logged a session; false means they missed.\n public void logDay(boolean studied)\n {\n // YOUR CODE HERE\n\n }\n\n // PART B\n // Simulates days consecutive days. For each day, if Math.random() < studyRate\n // the student studied; otherwise they missed. Must call logDay for every day.\n // Returns the total number of days studied.\n public int simulateTerm(int days, double studyRate)\n {\n // YOUR CODE HERE\n\n }\n\n public int getPoints() { return points; }\n public int getDayStreak() { return dayStreak; }\n\n // TEST MAIN (do not modify)\n public static void main(String[] args)\n {\n System.out.println(\"=== Part A: logDay() ===\");\n StudyStreak s = new StudyStreak(500);\n\n s.logDay(true);\n System.out.println(\"Day 1 (studied) points: \" + s.getPoints() + \" (expected 600) streak: \" + s.getDayStreak() + \" (expected 1)\");\n\n s.logDay(true);\n System.out.println(\"Day 2 (studied) points: \" + s.getPoints() + \" (expected 700) streak: \" + s.getDayStreak() + \" (expected 2)\");\n\n s.logDay(true);\n System.out.println(\"Day 3 (studied) points: \" + s.getPoints() + \" (expected 800) streak: \" + s.getDayStreak() + \" (expected 3)\");\n\n s.logDay(true);\n System.out.println(\"Day 4 (studied) points: \" + s.getPoints() + \" (expected 900) streak: \" + s.getDayStreak() + \" (expected 4)\");\n\n s.logDay(true); // dayStreak was 4 — bonus applies!\n System.out.println(\"Day 5 (studied) points: \" + s.getPoints() + \" (expected 1050) streak: \" + s.getDayStreak() + \" (expected 5)\");\n\n s.logDay(false);\n System.out.println(\"Day 6 (missed) points: \" + s.getPoints() + \" (expected 1020) streak: \" + s.getDayStreak() + \" (expected 0)\");\n\n System.out.println(\"\");\n System.out.println(\"=== Part B: simulateTerm() ===\");\n\n StudyStreak s2 = new StudyStreak(0);\n int d1 = s2.simulateTerm(10, 1.0);\n System.out.println(\"studyRate=1.0, 10 days studied: \" + d1 + \" (expected 10)\");\n\n StudyStreak s3 = new StudyStreak(0);\n int d2 = s3.simulateTerm(10, 0.0);\n System.out.println(\"studyRate=0.0, 10 days studied: \" + d2 + \" (expected 0)\");\n\n StudyStreak s4 = new StudyStreak(0);\n int d3 = s4.simulateTerm(0, 0.8);\n System.out.println(\"studyRate=0.8, 0 days studied: \" + d3 + \" (expected 0)\");\n\n StudyStreak s5 = new StudyStreak(0);\n int d4 = s5.simulateTerm(50, 0.6);\n System.out.println(\"studyRate=0.6, 50 days studied: \" + d4 + \" (expected roughly 30)\");\n }\n}\n```\n\n---\n\n## Part A — logDay(boolean studied) *(4 points)*\n\nWrite the `logDay` method. The parameter `studied` is `true` if the student logged a session and `false` if they missed. Update `points` and `dayStreak` according to the rules in the table above.\n\n**Trace** (starting from `new StudyStreak(500)`):\n\n| Call # | studied | points before | dayStreak before | points after | dayStreak after |\n|---|---|---|---|---|---|\n| 1st | true | 500 | 0 | 600 | 1 |\n| 2nd | true | 600 | 1 | 700 | 2 |\n| 3rd | true | 700 | 2 | 800 | 3 |\n| 4th | true | 800 | 3 | 900 | 4 |\n| 5th | true | 900 | 4 | 1050 | 5 |\n| 6th | false | 1050 | 5 | 1020 | 0 |\n\n---\n\n## Part B — simulateTerm(int days, double studyRate) *(5 points)*\n\nSimulate `days` days. For each day, if `Math.random() < studyRate` the student studied; otherwise they missed. Return the total number of days studied.\n\n> **Required:** You **must** call `logDay` for every day — `true` if studied, `false` if missed. No call to `logDay` = 0 points for Part B.\n\n| days | studyRate | simulateTerm returns |\n|---|---|---|\n| 10 | 1.0 | 10 (always studies) |\n| 10 | 0.0 | 0 (never studies) |\n| 0 | 0.8 | 0 (no days) |\n\n---\n\n**Submit your complete `StudyStreak` class including both methods and the unchanged main.**",
"rubric": "AP Computer Science A - Scoring Rubric - Teacher Copy\nStudyStreak - Methods and Control Structures (REASSESSMENT)\n9 points total - Do not share with students before grading\n\nPOINT 1 Adds 100 to points on a studied day when dayStreak < 4 before the day.\nPOINT 2 Adds 150 total (not just 50) when dayStreak >= 4 before the day (streak bonus case).\nPOINT 3 Subtracts 30 from points on a missed day and resets dayStreak to 0.\nPOINT 4 Increments dayStreak by 1 on every studied day (both streak and non-streak).\nPOINT 5 logDay method header correct: public void logDay(boolean studied).\nPOINT 6 simulateTerm loops exactly days times (0 iterations when days = 0).\nPOINT 7 Correctly determines outcome: Math.random() < studyRate means studied.\nPOINT 8 Calls logDay(true) on studied days and logDay(false) on missed days every iteration.\nPOINT 9 Tracks and returns the count of days studied.\n\nPenalty: No call to logDay = 0 points for Part B (points 6-9 at risk).\n\nCommon errors:\n- Using > 4 instead of >= 4 for the streak bonus threshold\n- Adding only 50 instead of 150 total on a streak day\n- Forgetting to increment dayStreak on studied days\n- Not resetting dayStreak to 0 on missed days\n- Forgetting to call logDay for missed days in simulateTerm\n\nSAMPLE ANSWER:\npublic void logDay(boolean studied) {\n if (studied) {\n if (dayStreak >= 4) {\n points += 150;\n } else {\n points += 100;\n }\n dayStreak++;\n } else {\n points -= 30;\n dayStreak = 0;\n }\n}\n\npublic int simulateTerm(int days, double studyRate) {\n int count = 0;\n for (int i = 0; i < days; i++) {\n boolean studied = Math.random() < studyRate;\n logDay(studied);\n if (studied) count++;\n }\n return count;\n}",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Q3: TestScoreList — Array/ArrayList (REASSESS)",
"prompt": "## Free Response Question 3 (Reassessment) — TestScoreList\n\nThis question involves a class that manages a list of student test scores using an `ArrayList<Integer>`. You will write **two methods** for the `TestScoreList` class.\n\n**Directions:** Write the complete method body for each part. Your solution must work correctly in all cases. Assume all necessary Java classes have been imported.\n\n---\n\n### The TestScoreList Class\n\n```java\nimport java.util.ArrayList;\n\npublic class TestScoreList\n{\n private ArrayList<Integer> scores;\n\n public TestScoreList()\n {\n scores = new ArrayList<Integer>();\n }\n\n public void addScore(int score)\n {\n scores.add(score);\n }\n\n public int getSize()\n {\n return scores.size();\n }\n\n // Part (a) - you will write this method\n public int getLowestScore()\n {\n /* to be implemented */\n }\n\n // Part (b) - you will write this method\n public int removeFailingScores(int passingScore)\n {\n /* to be implemented */\n }\n\n public static void main(String[] args)\n {\n System.out.println(\"=== Part A: getLowestScore() ===\");\n\n TestScoreList t1 = new TestScoreList();\n for (int s : new int[]{85, 62, 91, 78, 55, 88}) t1.addScore(s);\n System.out.println(\"Lowest: \" + t1.getLowestScore() + \" (expected 55)\");\n\n TestScoreList t2 = new TestScoreList();\n System.out.println(\"Empty: \" + t2.getLowestScore() + \" (expected 0)\");\n\n TestScoreList t3 = new TestScoreList();\n for (int s : new int[]{90, 90, 90}) t3.addScore(s);\n System.out.println(\"All same: \" + t3.getLowestScore() + \" (expected 90)\");\n\n System.out.println(\"\");\n System.out.println(\"=== Part B: removeFailingScores() ===\");\n\n TestScoreList t4 = new TestScoreList();\n for (int s : new int[]{85, 62, 91, 78, 55, 88}) t4.addScore(s);\n int r1 = t4.removeFailingScores(70);\n System.out.println(\"passingScore=70 removed: \" + r1 + \" (expected 2) size after: \" + t4.getSize() + \" (expected 4)\");\n\n TestScoreList t5 = new TestScoreList();\n for (int s : new int[]{85, 62, 91, 78, 55, 88}) t5.addScore(s);\n int r2 = t5.removeFailingScores(90);\n System.out.println(\"passingScore=90 removed: \" + r2 + \" (expected 5) size after: \" + t5.getSize() + \" (expected 1)\");\n\n TestScoreList t6 = new TestScoreList();\n for (int s : new int[]{70, 70, 70}) t6.addScore(s);\n int r3 = t6.removeFailingScores(70);\n System.out.println(\"passingScore=70 removed: \" + r3 + \" (expected 0) size after: \" + t6.getSize() + \" (expected 3)\");\n\n TestScoreList t7 = new TestScoreList();\n for (int s : new int[]{45, 50, 55}) t7.addScore(s);\n int r4 = t7.removeFailingScores(60);\n System.out.println(\"passingScore=60 removed: \" + r4 + \" (expected 3) size after: \" + t7.getSize() + \" (expected 0)\");\n }\n}\n```\n\n---\n\n### Part (a) — `getLowestScore` *(4 points)*\n\nWrite the `getLowestScore` method, which returns the lowest score in `scores`. If the list is empty, return `0`.\n\n| scores list | getLowestScore() returns |\n|---|---|\n| `[85, 62, 91, 78, 55, 88]` | `55` |\n| `[70]` | `70` |\n| `[90, 90, 90]` | `90` |\n| `[]` (empty) | `0` |\n\n---\n\n### Part (b) — `removeFailingScores` *(5 points)*\n\nWrite the `removeFailingScores` method, which removes every entry from `scores` whose value is **strictly less than** `passingScore`. The order of the remaining entries must be preserved. The method returns the number of entries removed.\n\n> **Note:** A score equal to `passingScore` is **not** removed.\n\n| scores (before) | passingScore | Returns | scores (after) |\n|---|---|---|---|\n| `[85, 62, 91, 78, 55, 88]` | 70 | 2 | `[85, 91, 78, 88]` |\n| `[85, 62, 91, 78, 55, 88]` | 90 | 5 | `[91]` |\n| `[70, 70, 70]` | 70 | 0 | `[70, 70, 70]` |\n| `[45, 50, 55]` | 60 | 3 | `[]` |\n\n---\n\n**Submit your complete `TestScoreList` class including both methods and the unchanged main.**",
"rubric": "AP Computer Science A - Scoring Rubric - Teacher Copy\nTestScoreList - Array/ArrayList (REASSESSMENT)\n9 points total - Do not share with students before grading\n\nPART A\ngetLowestScore() - 4 points\n1 Returns 0 without throwing an exception when the list is empty.\n1 Initializes a min variable to a sensible starting value before traversal (e.g., first element, Integer.MAX_VALUE, or a large value).\n1 Correctly traverses all elements of the ArrayList.\n1 Returns the minimum value found.\n\nCommon errors: Not handling empty list (throws IndexOutOfBoundsException).\nInitializing min to 0 causes incorrect results when all scores are above 0 — returns 0 instead of actual minimum.\nReturning inside the loop before all elements are checked.\n\nPART B\nremoveFailingScores() - 5 points\n1 Initializes a removal count to 0 before iteration.\n1 Uses a correct traversal that avoids the index-drift bug — backward loop (size-1 to 0) or forward loop with index adjustment after removal.\n1 Condition is strictly less than (<), not less than or equal (<=).\n1 Removes qualifying elements using remove(index).\n1 Returns the count of removed elements.\n\nCommon errors (major trap): Forward iteration with removal causes index drift — elements immediately after a removed one are silently skipped.\nUsing <= instead of < incorrectly removes scores equal to passingScore (fails the all-equal boundary case).\n\nSAMPLE ANSWER:\npublic int getLowestScore() {\n if (scores.isEmpty()) return 0;\n int min = scores.get(0);\n for (int i = 1; i < scores.size(); i++) {\n if (scores.get(i) < min) min = scores.get(i);\n }\n return min;\n}\n\npublic int removeFailingScores(int passingScore) {\n int count = 0;\n for (int i = scores.size() - 1; i >= 0; i--) {\n if (scores.get(i) < passingScore) {\n scores.remove(i);\n count++;\n }\n }\n return count;\n}",
"max_submissions": 1,
"is_visible": 1,
"tab_monitoring_enabled": 1
},
{
"title": "AP Q4: ConcertHall — 2D Arrays (Practice)",
"prompt": "## Free Response Question 4 — ConcertHall (2D Arrays)\n\nYou and your friends are trying to snag seats at the hottest concert of the year. The venue's seating app tracks availability using a 2D array: `0` means the seat is empty, `1` means it's reserved. Your job is to help the app find open seats for groups of fans.\n\nYou will write **two methods** for the `ConcertHall` class.\n\n**Directions:** Write the complete method body for each part. Assume all necessary imports are in place.\n\n---\n\n### The ConcertHall Class\n\n```java\npublic class ConcertHall\n{\n private int[][] seats;\n // seats[r][c] == 0 → empty seat\n // seats[r][c] == 1 → reserved seat\n\n public ConcertHall(int[][] seatData)\n {\n seats = seatData;\n }\n\n public int getNumRows() { return seats.length; }\n public int getNumCols() { return seats[0].length; }\n\n // Part (a) — you will write this method\n public boolean hasConsecutiveSeats(int row, int groupSize)\n {\n /* to be implemented in Part (a) */\n }\n\n // Part (b) — you will write this method\n public int findBestRow(int groupSize)\n {\n /* to be implemented in Part (b) */\n }\n\n public static void main(String[] args)\n {\n int[][] hall = {\n {1, 0, 0, 1, 0, 0, 0, 1}, // row 0\n {0, 1, 1, 0, 0, 0, 1, 0}, // row 1\n {0, 0, 1, 1, 0, 1, 0, 0}, // row 2\n {1, 1, 1, 1, 1, 1, 1, 1}, // row 3 (sold out!)\n {0, 0, 0, 0, 0, 1, 1, 0} // row 4\n };\n\n ConcertHall ch = new ConcertHall(hall);\n\n System.out.println(\"=== Part A: hasConsecutiveSeats ===\");\n System.out.println(ch.hasConsecutiveSeats(0, 3) + \" (expected true)\");\n System.out.println(ch.hasConsecutiveSeats(0, 4) + \" (expected false)\");\n System.out.println(ch.hasConsecutiveSeats(1, 3) + \" (expected true)\");\n System.out.println(ch.hasConsecutiveSeats(3, 1) + \" (expected false)\");\n System.out.println(ch.hasConsecutiveSeats(4, 5) + \" (expected true)\");\n\n System.out.println(\"\");\n System.out.println(\"=== Part B: findBestRow ===\");\n System.out.println(ch.findBestRow(3) + \" (expected 0)\");\n System.out.println(ch.findBestRow(5) + \" (expected 4)\");\n System.out.println(ch.findBestRow(9) + \" (expected -1)\");\n }\n}\n```\n\n---\n\n### Part (a) — `hasConsecutiveSeats` *(4 points)*\n\nWrite the `hasConsecutiveSeats` method. It returns `true` if the given row contains **at least** `groupSize` consecutive empty seats (zeros in a row), and `false` otherwise.\n\n| Row (0-indexed) | Seat values | groupSize | Returns |\n|---|---|---|---|\n| 0 | `[1, 0, 0, 1, 0, 0, 0, 1]` | 3 | `true` (cols 4–6 are empty) |\n| 0 | `[1, 0, 0, 1, 0, 0, 0, 1]` | 4 | `false` (no run of 4) |\n| 1 | `[0, 1, 1, 0, 0, 0, 1, 0]` | 3 | `true` (cols 3–5 are empty) |\n| 3 | `[1, 1, 1, 1, 1, 1, 1, 1]` | 1 | `false` (completely sold out) |\n| 4 | `[0, 0, 0, 0, 0, 1, 1, 0]` | 5 | `true` (cols 0–4 are empty) |\n\n> **Hint:** Keep a running count of consecutive empty seats. Reset it to 0 whenever you hit a `1`.\n\n---\n\n### Part (b) — `findBestRow` *(5 points)*\n\nWrite the `findBestRow` method. It returns the **index of the first row** that has at least `groupSize` consecutive empty seats. If no such row exists, return `-1`.\n\nYou may call `hasConsecutiveSeats` as a helper.\n\n| groupSize | Returns | Why |\n|---|---|---|\n| 3 | `0` | Row 0 is the first row with 3+ consecutive empty seats |\n| 5 | `4` | Row 4 is the first row with 5+ consecutive empty seats |\n| 9 | `-1` | No row has 9 consecutive empty seats |\n\n---\n\n**Submit your complete `ConcertHall` class with both methods and the unchanged main.**",
"rubric": "AP Computer Science A - Scoring Rubric - Teacher Copy\nConcertHall - 2D Arrays\n9 points total - Do not share with students before grading\n\nPART A\nhasConsecutiveSeats(int row, int groupSize) - 4 points\n\n1 Initializes a consecutive-empty counter to 0 before the loop.\n1 Iterates through all columns of seats[row] (correct bounds: 0 to seats[row].length - 1).\n1 Resets counter to 0 when a reserved seat (1) is found; increments when an empty seat (0) is found.\n1 Returns true as soon as counter reaches groupSize; returns false after the loop ends.\n\nCommon errors:\n- Using seats.length instead of seats[row].length for the column bound.\n- Returning false immediately inside the loop on the first 1, skipping later runs.\n- Initializing counter outside the method or never resetting it.\n\nPART B\nfindBestRow(int groupSize) - 5 points\n\n1 Iterates through all rows with a loop (0 to seats.length - 1).\n1 Calls hasConsecutiveSeats(r, groupSize) for each row (or reimplements equivalent logic).\n1 Returns the current row index immediately when a qualifying row is found (first match, not last).\n1 Returns -1 only after all rows have been checked without a match.\n1 Does not access out-of-bounds indices.\n\nCommon errors:\n- Returning last matching row instead of first.\n- Missing return -1 at the end (compile error).\n- Copying Part A logic incorrectly instead of calling the helper.\n\nSAMPLE ANSWER:\n\npublic boolean hasConsecutiveSeats(int row, int groupSize) {\n int count = 0;\n for (int c = 0; c < seats[row].length; c++) {\n if (seats[row][c] == 0) {\n count++;\n if (count >= groupSize) return true;\n } else {\n count = 0;\n }\n }\n return false;\n}\n\npublic int findBestRow(int groupSize) {\n for (int r = 0; r < seats.length; r++) {\n if (hasConsecutiveSeats(r, groupSize)) return r;\n }\n return -1;\n}",
"max_submissions": 2,
"is_visible": 1,
"tab_monitoring_enabled": 0
}
]
}