-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsa_grader_config.py
42 lines (40 loc) · 51 KB
/
csa_grader_config.py
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
QUESTIONS = '''2023 AP Computer Science A Free-Response Questions @ 2023 College Board. College Board, Advanced Placement, AP, AP Central, and the acorn logo are registered trademarks Of College Board. Visit College Board on the web: collegeboard.org. AP Central is the offcial online home for the AP Program: apcentral.collegeboard.org. APO Computer Science A 2023 Free-Response Questions COMPUTER SCIENCE A SECTION 11 Time—I hour and 30 minutes 4 Questions Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. You may plan your answers in this orange booklet, but no credit will be given for anything written in this booklet. You will only earn credit for what you write in the separate Free Response booklet. Notes: Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. GO ON TO THE NEXT PAGE. 0 2023 College Board. Visit College Board on the web: collegeboard.org. 1. This question involves the AppointmentBook class, which provides methods for students to schedule appointments with their teacher. Appointments can be scheduled during one of eight class periods during the school day, numbered I through 8. A requested appointment has a duration, which is the number of minutes the appointment will last. The 60 minutes within a period are numbered 0 through 59. In order for an appointment to be scheduled, the teacher must have a block of consecutive, available minutes that contains at least the requested number of minutes in a requested period. Scheduled appointments must start and end within the same period. The AppointmentBook class contains two helper methods, isMinuteFree and reserveB10ck. You will write two additional methods of the AppointmentBook class. public class AppointmentBook * Returns true if minute in period is available for an appointment and returns * false otherwise Preconditions: 1 period 8; O minute <= 59 private boolean isMinuteFree ( int period, int minute) / * implementation not shown * / } * Marks the block of minutes that starts at startMinute in period and is duration minutes long as reserved for an appointment Preconditions: 1 period 8; 0 1 duration 60 private void reserveB10ck ( int period, / * implementation not shown * / } startMinute 59; int startMinute, int duration) * * Searches for the first block of duration free minutes during period, as described in part (a). Returns the first minute in the block if such a block is found or returns —1 if no such block is found. Preconditions: 1 period <= 8; 1 duration <= 60 public int findFreeB10ck (int period, int duration) / * to be implemented in part (a) * * * Searches periods from startPeriod to endperiod, inclusive, for a block of duration free minutes, as described in part (b). If such a block is found, calls reserveB10ck to reserve the block of minutes and returns true; otherwise returns false. Preconditions: 1 startPeriod endperiod 8; 1 duration int endPeriod, 60 public boolean makeAppointment (int startperiod, int duration) / * to be implemented in part (b) * / / / There may be instance variables, constructors, and methods that are not shown. (a) Write the findFreeB10ck method, which searches period for the first block of free minutes that is duration minutes long. If such a block is found, findFreeB10ck returns the first minute in the block. Otherwise, findFreeB10ck returns -1. The findFreeB10ck method uses the helper method isMinuteFree, which returns true if a particular minute is available to be included in a new appointment and returns false if the minute is unavailable. Consider the following list of unavailable and available minutes in period 2. Minutes in Period 2 Available? 0—9 10 minutes 10—14 (5 minutes) 15—29 15 minutes 30—44 (15 minutes) 45—49 5 minutes 50—59 (IO minutes) No Yes No Yes No Yes The method call findFreeB10ck (2, 15) would return 30 to indicate that a 15-minute block starting with minute 30 is available. No steps should be taken as a result of the call to findFreeB10ck to mark those 15 minutes as unavailable. The method call findFreeB10ck (2, 9) would also return 30. Whenever there are multiple blocks that satisfy the requirement, the earliest starting minute is returned. The method call findFreeB10ck (2, 20) would return —1, since no 20-minute block of available minutes exists in period 2. Complete method findFreeB10ck. You must use isMinuteFree appropriately in order to receive full credit. Searches for the first block of duration free minutes during period, as described in part (a). Returns the first minute in the block if such a block is found or returns -1 if no •k such block is found. Preconditions: 1 period 8; 1 public int findFreeB10ck ( int period, duration 60 int duration) Begin your response at the top of a new page in the separate Free Response booklet and fill in the appropriate circle at the top of each page to indicate the question number. If there are multiple parts to this question, write the part letter with your response. (b) Write the makeAppointment method, which searches the periods from startPeriod to endPeriod, inclusive, for the earliest block of duration available minutes in the lowest-numbered period. If such a block is found, the makeAppointment method calls the helper method reserveB10ck to mark the minutes in the block as unavailable and returns true. If no such block is found, the makeAppointment method returns false. Consider the following list of unavailable and available minutes in periods 2, 3, and 4 and three successive calls to makeAppointment. Period Minutes 2 2 2 3 3 3 4 4 4 4 0—24 25 minutes 25—29 (5 minutes) 30—59 30 minutes 0—14 (15 minutes) 15—40 26 minutes 41—59 19 minutes (5 minutes) 5—29 25 minutes 30—43 (14 minutes) 44—59 16 minutes Available? No Yes No Yes No Yes No Yes No Yes The method call makeAppointment (2, 4, 22) returns true and results in the minutes 5 through 26, inclusive, in period 4 being marked as unavailable. The method call makeAppointment (3, 4, 3) returns true and results in the minutes 0 through 2, inclusive, in period 3 being marked as unavailable. The method call makeAppointment (2, 4, 30) returns false, since there is no block of 30 available minutes in periods 2, 3, or 4. The following shows the updated list of unavailable and available minutes in periods 2, 3, and 4 after the three example method calls are complete. Period 2 2 2 3 3 3 3 4 4 4 4 Minutes 0—24 25 minutes 25—29 (5 minutes) 30-59 30 minutes 0—2 3 minutes 3—14 12 minutes 15—40 26 minutes 41—59 (19 minutes) 0—26 27 minutes 27—29 (3 minutes) 30—43 14 minutes 44—59 (16 minutes) Available? No Yes No No Yes No Yes No Yes No Yes Complete method makeAppointment. Assume that findFreeB10ck works as intended, regardless of what you wrote in part (a). You must use findFreeB10ck and reserveB10ck appropriately in order to receive full credit. * * * * •k Searches periods from startperiod to endPeriod, inclusive, for a block of duration free minutes, as described in part (b). If such a block is found, calls reserveB10ck to reserve the block of minutes and returns true; otherwise returns false. Preconditions: 1 startPeriod endPeriod 8; 1 duration 60 public boolean makeAppointment ( int startperiod, int duration) int endPeriod, Begin your response at the top of a new page in the separate Free Response booklet and fill in the appropriate circle at the top of each page to indicate the question number. If there are multiple parts to this question, write the part letter with your response. Class information for this question public class AppointmentBook private boolean isMinuteFree ( int period, int minute) private void reserveB10ck (int period, int startMinute, int duration) public int findFreeB10ck (int period, int duration) public boolean makeAppointment ( int startPeriod, int endperiod, int duration) 2. This question involves methods that distribute text across lines of an electronic sign. The electronic sign and the text to be displayed on it are represented by the Sign class. You will write the complete Sign class, which contains a constructor and two methods. The Sign class constructor has two parameters. The first parameter is a String that contains the message to be displayed on the sign. The second parameter is an int that contains the width of each line of the sign. The width is the positive maximum number of characters that can be displayed on a single line of the sign. A sign contains as many lines as are necessary to display the entire message. The message is split among the lines of the sign without regard to spaces or punctuation. Only the last line of the sign may contain fewer characters than the width indicated by the constructor parameter. The following are examples of a message displayed on signs of different widths. Assume that in each example, the sign is declared with the width specified in the first column of the table and with the message " Everything on sale, please come in", which contains 34 characters. Width of the Sign 15 17 40 Sign Display Everything on s ale, please com e in Everything on sat e, please come in Everything on sale, please come in In addition to the constructor, the Sign class contains two methods. The numberOfLines method returns an int representing the number of lines needed to display the text on the sign. In the previous examples, numberOfLines would return 3, 2, and 1, respectively, for the sign widths shown in the table. The getLines method returns a String containing the message broken into lines separated by semicolons (;) or returns null if the message is the empty string. The constructor parameter that contains the message to be displayed will not include any semicolons. As an example, in the first row of the preceding table, getLines would return "Everything on s; ale, please com;e in". No semicolon should appear at the end of the String returned by getLines. Statement String str; int x; Sign sign1 = new Sign ( "ABC222DE" , 3); sign I . numberOfLines ( ) ; str = str = The following table contains a sample code execution sequence and the corresponding results. The code execution sequence appears in a class other than Sign. "ABC; 222; signl . getLines ( ) ; sign 1 . getLines ( ) ; new 10); Sign sign2 = Sign ( " ABCD" , sign2 . numberOfLines ( ) ; = sign2 . getLines ( ) ; str Sign sign3 = new Sign ( " ABCDEF" , x = sign3 . numberOfLines ( ) ; sign3 .getLines ( ) ; str = Sign sign4 = new Sign("", = sign4 . numberOfLines ( ) ; x = sign4 .getLines ( ) ; str Sign sign5 = new Sign ( , 2); sign5. numberOfLines ( ) ; str = sign5 .getLines ( ) ; Method Call Return Value (blank if none) 3 "ABC; 222 ; DE DE " 1 " ABCD " 1 " ABCDEF " null 4 Explanation The message for signl contains 8 characters, and the sign has lines of width 3. The sign needs three lines to display the 8-character message on a sign with lines of width 3. Semicolons separate the text displayed on the first, second, and third lines of the si n. Successive calls to getLines return the same value. The message for sign2 contains 4 characters, and the si n has lines of width IO. The sign needs one line to display the 4-character message on a sign with lines of width IO. No semicolon appears, since the text to be dis la ed fits on the first line of the si n. The message for sign3 contains 6 characters, and the si n has lines of width 6. The sign needs one line to display the 6-character message on a sign with lines of width 6. No semicolon appears, since the text to be dis la ed fits on the first line of the si n. The message for sign4 is an empty string. There is no text to dis la . There is no text to dis la . The message for sign5 contains 8 characters, and the si n has lines of width 2. The sign needs four lines to display the 8-character message on a sign with lines of width 2. Semicolons separate the text displayed on the four lines of the si n. Write the complete Sign class. Your implementation must meet all specifications and conform to the examples shown in the preceding table. 3. This question involves the analysis of weather data. The following WeatherData class has an instance variable, temperatures, which contains the daily high temperatures recorded on consecutive days at a particular location. The class also contains methods used to analyze that data. You will write two methods of the WeatherData class. public class WeatherData / ** Guaranteed not to be null and to contain only non-nu11 entries * / private ArrayList<Doub1e> temperatures ; * Cleans the data by removing from temperatures all values that are less than * lower and all values that are greater than upper, as described in part (a) public void cleanData (double lower, double upper) { / * to be implemented in part (a) * / } * Returns the length of the longest heat wave foundin temperatures, as described in Precondition: There is at least one heat wave in temperatures based on threshold. •k public int longestHeatWave (double threshold) { / * to be implemented in part (b) * / / / There may be instance variables, constructors, and methods that are not shown. (a) Write the cleanData method, which modifies the temperatures instance variable by removing all values that are less than the lower parameter and all values that are greater than the upper parameter. The order of the remaining values in temperatures must be maintained. For example, consider a WeatherData object for which temperatures contains the following. The three shaded values shown would be removed by the method call cleanData (85 . O, 120 . O) . The following shows the contents of temperatures after the three shaded values are removed as a result of the method call cleanData (85 . 0, 120 . 0) . Complete method cleanData. * Cleans the data by removing from temperatures all values that are less than * lower and all values that are greater than upper, as described in part (a) public void cleanData (double lower, double upper) Begin your response at the top of a new page in the separate Free Response booklet and fill in the appropriate circle at the top of each page to indicate the question number. If there are multiple parts to this question, write the part letter with your response. (b) Write the longestHeatWave method, which returns the length of the longest heat wave found in the temperatures instance variable. A heat wave is a sequence of two or more consecutive days with a daily high temperature greater than the parameter threshold. The temperatures instance variable is guaranteed to contain at least one heat wave based on the threshold parameter. For example, consider the following contents of temperatures. In the following sample contents of temperatures, all heat waves based on the threshold temperature of 100 . 5 are shaded. The method call longestHeatWave (100 . 5) would return 3, which is the length of the longest heat wave. In the following sample contents of temperatures, all heat waves based on the threshold temperature of 95.2 are shaded. The method call longestHeatWave (95 . 2) would return 4, which is the length of the longest heat wave. Complete method longestHeatWave. * Returns the length of the longest heat wave found in temperatures, as described in Precondition: There is at least one heat wave in temperatures based on threshold. public int longes tHeatWave ( double threshold) Begin your response at the top of a new page in the separate Free Response booklet and fill in the appropriate circle at the top of each page to indicate the question number. If there are multiple parts to this question, write the part letter with your response. Class information for this question public class WeatherData private ArrayList<Doub1e> temperatures public void cleanData ( double lower, double upper) public int longestHeatWave (double threshold) 4. This question involves pieces of candy in a box. The Candy class represents a single piece of candy. public class Candy / ** Returns a String representing the flavor of this piece of candy * / public String getF1avor ( ) / * implementation not shown * / } / / There may be instance variables, constructors, and methods that are not shown. The BoxOfCandy class represents a candy box where the candy is arranged in a rectangular grid. The instance variable of the class, box, is a rectangular two-dimensional array of Candy objects. A location in the candy box may contain a piece of candy or may be empty. A piece of candy is represented by a Candy object. An empty location is represented by null. You will write two methods of the BoxOfCandy class. public class BoxOfCandy / ** box contains at least one row and is initialized in the constructor. * / private Candy [J [J box; * * Moves one piece of candy in column col, if necessary and possible, so that the box element in row 0 of column col contains a piece of candy, as described in part (a). Returns false if there is no piece of candy in column col and returns true otherwise. Precondition: col is a valid column index in box. public boolean moveCandyToFirstRow ( int col ) / * to be implemented in part (a) * Removes from box and returns a piece of candy with flavor specified by the parameter, or * returns null if no such piece is found, as described in part (b) public Candy removeNextByF1avor (String flavor) / * to be implemented in part (b) * / / / There may be instance variables, constructors, and methods that are not shown. (a) Write the moveCandyToFirstRow method, which attempts to ensure that the box element at row O and column col contains a piece of candy, using the following steps. • If the element at row 0 and column col already contains a piece of candy, then box is unchanged and the method returns true. • If the element at row O and column col does not contain a piece of candy, then the method searches the remaining rows of column col for a piece of candy. If a piece of candy can be found in column col, it is moved to row 0, its previous location is set to null, and the method returns true; otherwise, the method returns false. In the following example, the grid represents the contents of box. An empty square in the grid is null in box. A non-empty square in the grid represents a box element that contains a Candy object. The string in the square of the grid indicates the flavor of the piece of candy. o 1 2 3 1 lime O "orange" 1 emon 2 "cherry" "grape" The method call moveCandyToFirstRow (0) returns false because the box element at row O and column C) does not contain a piece of candy and there are no pieces of candy in column O that can be moved to row O. The contents of box are unchanged. The method call moveCandyToFirstRow (1) returns true because the box element at row 0 and column 1 already contains a piece of candy. The contents of box are unchanged. The method call moveCandyToFirstRow (2) moves one of the two pieces of candy in column 2 to row C) of column 2, sets the previous location of the piece of candy that was moved to null, and returns true. The new contents of box could be either of the following. 1 2 3 1 lime " orange " " lemon " 2 "cherry" " grape " o 1 or 2 3 1 1 ime O "orange" t' lemon " 2 grape "cherry" Complete the moveCandyToFirstRow method. * * Moves one piece of candy in column col, if necessary and possible, so that the box element in row 0 of column col contains a piece of candy, as described in part (a). Returns false if there is no piece of candy in column col and returns true otherwise. Precondition: col is a valid column index in box. public boolean moveCandyToFirstRow ( int COI) Begin your response at the top of a new page in the separate Free Response booklet and fill in the appropriate circle at the top of each page to indicate the question number. If there are multiple parts to this question, write the part letter with your response. Class information for this question public class Candy. public String getF1avor ( ) public class BoxOfCandy. private Candy [ ] [ ] box public boolean moveCandyToFirstRow ( int col) public Candy removeNextByF1avor ( String flavor) (b) Write the removeNextByF1avor method, which attempts to remove and return one piece of candy from the box. The piece of candy to be removed is the first piece of candy with a flavor equal to the parameter flavor that is encountered while traversing the candy box in the following order: the last row of the box is traversed from left to right, then the next-to-last row of the box is traversed from left to right, etc., until either a piece of candy with the desired flavor is found or until the entire candy box has been searched. If the removeNextByF1avor method finds a Candy object with the desired flavor, the corresponding box element is assigned null, all other box elements are unchanged, and the removed Candy object is returned. Otherwise, box is unchanged and the method returns null. The following examples show three consecutive calls to the removeNextByF1avor method. The traversal of the candy box always begins in the last row and first column of the box. The following grid shows the contents of box before any of the removeNextByF1avor method calls. 1 2 o 1 ime " O " orange" cherry" 1 t' 1 ime 2 1 emon 3 " lemon " " lime " 4 " lime" O "orange" The method call removeNextByF1avor ( "cherry") removes and returns the Candy object located in row 2 and column O. The following grid shows the updated contents of box. 1 o " lime " O 1 " lime " 2 " lemon " 3 " lemon " " lime " " orange" 2 4 " lime " O "orange" The method call removeNextByF1avor ( " lime " ) removes and returns the Candy object located in row 1 and column 3. The following grid shows the updated contents of box. 1 1 ime 1 lime O 2 " lemon " 3 lemon " orange" 2 4 " lime " O "orange " The method call removeNextByF1avor ( "grape" ) returns null because no grape-flavored candy is found. The contents of box are unchanged. Complete the removeNextByF1avor method. * Removes from box and returns a piece of candy with flavor specified by the parameter, or returns null if no such piece is found, as described in part (b) public Candy removeNextByF1avor (String flavor) Begin your response at the top of a new page in the separate Free Response booklet and fill in the appropriate circle at the top of each page to indicate the question number. If there are multiple parts to this question, write the part letter with your response. Class information for this question public class Candy public String getF1avor ( ) public class BoxOfCandy private Candy [J [ ] box public boolean moveCandyToFirstRow ( int col ) public Candy removeNextByF1avor ( String flavor)'''
SCORING_GUIDE = '''AP® Computer Science A Scoring Guidelines 2023 © 2023 College Board. College Board, Advanced Placement, AP, AP Central, and the acorn logo are registered trademarks of College Board. Visit College Board on the web: collegeboard.org. AP Central is the official online home for the AP Program: apcentral.collegeboard.org. AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Applying the Scoring Criteria Apply the question scoring criteria first, which always takes precedence. Penalty points can only be deducted in a part of the question that has earned credit via the question rubric. No part of a question (a, b, c) may have a negative point total. A given penalty can be assessed only once for a question, even if it occurs multiple times or in multiple parts of that question. A maximum of 3 penalty points may be assessed per question. 1-Point Penalty v) Array/collection access confusion ([] get) w) Extraneous code that causes side-effect (e.g., printing to output, incorrect precondition check) x) Local variables used but none declared y) Destruction of persistent data (e.g., changing value referenced by parameter) z) Void method or constructor that returns a value No Penalty • Extraneous code with no side-effect (e.g., valid precondition check, no-op) • Spelling/case discrepancies where there is no ambiguity* • Local variable not declared provided other variables are declared in some part • private or public qualifier on a local variable • Missing public qualifier on class or constructor header • Keyword used as an identifier • Common mathematical symbols used for operators (× • ÷ ≤ ≥ <> ≠) • [] vs. () vs. <> • = instead of == and vice versa • length/size confusion for array, String, List, or ArrayList; with or without ( ) • Extraneous [] when referencing entire array • [i,j] instead of [i][j] • Extraneous size in array declaration, e.g., int[size] nums = new int[size]; • Missing ; where structure clearly conveys intent • Missing { } where indentation clearly conveys intent • Missing ( ) on parameter-less method or constructor invocations • Missing ( ) around if or while conditions *Spelling and case discrepancies for identifiers fall under the “No Penalty” category only if the correction can be unambiguously inferred from context, for example, “ArayList” instead of “ArrayList”. As a counterexample, note that if the code declares "int G=99, g=0;", then uses "while (G < 10)" instead of "while (g < 10)", the context does not allow for the reader to assume the use of the lower case variable. AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Question 1: Methods and Control Structures 9 points Canonical solution (a) public int findFreeBlock(int period, int duration) { int blockLength = 0; for (int minute = 0; minute < 60; minute++) { if (isMinuteFree(period, minute)) { blockLength++; if (blockLength == duration) { return minute – blockLength + 1; } } else { blockLength = 0; } } return -1; } 5 points (b) public boolean makeAppointment(int startPeriod, int endPeriod, int duration) { for (int period = startPeriod; period <= endPeriod; period++) { int minute = findFreeBlock(period, duration); if (minute != -1) { reserveBlock(period, minute, duration); return true; } } return false; } 4 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board (a) findFreeBlock Scoring Criteria Decision Rules 1 Loops over necessary minutes in an hour Responses can still earn the point even if they • loop over fewer than 60 minutes as long as at least (60 – duration + 1) minutes are included • loop over 60 minutes and use a boolean to indicate that a free block has been found 1 point 2 Calls isMinuteFree with period and another int parameter Responses can still earn the point even if they • call isMinuteFree with invalid parameters due to incorrect loop bounds Responses will not earn the point if they • use incorrect parameter types • order the parameters incorrectly • call the method on the class or on an object other than this (use of this is optional) 1 point 3 Keeps track of contiguous free minutes in a block (algorithm) Responses can still earn the point even if they • call isMinuteFree incorrectly Responses will not earn the point if they • fail to reset when a nonfree minute is found • call isMinuteFree with minutes >= 60 1 point 4 Checks whether a valid block of duration minutes has been found Responses can still earn the point even if they • maintain a boolean instead of accumulating the block length 1 point 5 Calculates and returns starting minute and -1 appropriately based on identified block (algorithm) Responses will not earn the point if they • are off by one on the returned value 1 point Total for part (a) 5 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board (b) makeAppointment Scoring Criteria Decision Rules 6 Loops over periods from startPeriod through endPeriod (no bounds errors) 1 point 7 Calls findFreeBlock and reserveBlock with correct number of int parameters, representing a period and minute as appropriate, and duration Responses can still earn the point even if they • use incorrect parameter values Responses will not earn the point if they • use incorrect parameter types • order the parameters incorrectly • call the methods on the class or on an object other than this (use of this is optional) 1 point 8 Guards call to method to reserve a block by determining that starting minute is not -1 1 point 9 Books correct appointment and returns appropriate boolean (algorithm) Responses can still earn the point even if they • have incorrect bounds in the loop • call findFreeBlock or reserveBlock incorrectly Responses will not earn the point if they • fail to return true or false • return before the call to reserveBlock 1 point 4 points Question-specific penalties None Total for question 1 9 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Alternate Canonical for Part (a) public int findFreeBlock(int period, int duration) { for (int startMin = 0; startMin < 60 – duration + 1; startMin++) { boolean isBlockFree = true; for (int min = 0; min < duration; min++) { if (!isMinuteFree(period, min + startMin)) { isBlockFree = false; } } if (isBlockFree) { return startMin; } } return -1; } AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Applying the Scoring Criteria Apply the question scoring criteria first, which always takes precedence. Penalty points can only be deducted in a part of the question that has earned credit via the question rubric. No part of a question (a, b, c) may have a negative point total. A given penalty can be assessed only once for a question, even if it occurs multiple times or in multiple parts of that question. A maximum of 3 penalty points may be assessed per question. 1-Point Penalty v) Array/collection access confusion ([] get) w) Extraneous code that causes side-effect (e.g., printing to output, incorrect precondition check) x) Local variables used but none declared y) Destruction of persistent data (e.g., changing value referenced by parameter) z) Void method or constructor that returns a value No Penalty • Extraneous code with no side-effect (e.g., valid precondition check, no-op) • Spelling/case discrepancies where there is no ambiguity* • Local variable not declared provided other variables are declared in some part • private or public qualifier on a local variable • Missing public qualifier on class or constructor header • Keyword used as an identifier • Common mathematical symbols used for operators (× • ÷ ≤ ≥ <> ≠) • [] vs. () vs. <> • = instead of == and vice versa • length/size confusion for array, String, List, or ArrayList; with or without ( ) • Extraneous [] when referencing entire array • [i,j] instead of [i][j] • Extraneous size in array declaration, e.g., int[size] nums = new int[size]; • Missing ; where structure clearly conveys intent • Missing { } where indentation clearly conveys intent • Missing ( ) on parameter-less method or constructor invocations • Missing ( ) around if or while conditions *Spelling and case discrepancies for identifiers fall under the “No Penalty” category only if the correction can be unambiguously inferred from context, for example, “ArayList” instead of “ArrayList”. As a counterexample, note that if the code declares "int G=99, g=0;", then uses "while (G < 10)" instead of "while (g < 10)", the context does not allow for the reader to assume the use of the lower case variable. AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Question 2: Class 9 points Canonical solution public class Sign { private String message; private int width; public Sign(String m, int w) { message = m; width = w; } public int numberOfLines() { int len = message.length(); if (len % width == 0) { return len / width; } else { return len / width + 1; } } public String getLines() { int linesNeeded = numberOfLines(); if (linesNeeded == 0) { return null; } String signLines = ""; for (int i = 1; i < linesNeeded; i++) { signLines += message.substring((i – 1) * width, i * width) + ";"; } return signLines + message.substring((linesNeeded – 1) * width); } } 9 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Sign Scoring Criteria Decision Rules 1 Declares class header: class Sign Responses will not earn the point if they • declare the class as something other than public 1 point 2 Declares appropriate private instance variable(s) and constructor initializes instance variables using appropriate parameters Responses can still earn the point even if they • store calculated values instead of the message and width, as long as the declared instance variables can collectively answer the questions and their values are computed from the parameters (correctly or incorrectly) Responses will not earn the point if they • declare the variable outside the class, or in the class within a method or constructor 1 point 3 Declares constructor header: Sign(String ___, int ___) Responses can still earn the point even if they • calculate values in the constructor that are returned by other methods, correctly or incorrectly, as long as the parameter types are correct Responses will not earn the point if they • declare the constructor as something other than public 1 point 4 Declares method headers: public int numberOfLines() public String getLines() Responses will not earn the point if they • omit either method • omit public or declare the method as something other than public 1 point 5 numberOfLines divides the message length by the line width Responses can still earn the point even if they • perform the division in a method other than numberOfLines • perform the division without using the division operator by counting line-widthsized portions of the message or by counting lines produced by the linedelimiting algorithm • incorrectly account for the final line • use a method name inconsistent with the examples, as long as it is recognizably equivalent 1 point 6 numberOfLines returns appropriate value (algorithm) Responses can still earn the point even if they • perform the return value calculation in the constructor • return a different number of lines than getLines produces, as long as the number returned is the correct number for the message 1 point AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board • return an incorrect number of lines for the message, as long as the number returned is exactly the number of lines produced by getLines • use a method name inconsistent with the examples, as long as it is recognizably equivalent Responses will not earn the point if they • incorrectly account for the final line 7 getLines returns null appropriately Responses can still earn the point even if they • identify null case in a method other than getLines • use an invalid call to length or == in guard for null return • use a method name inconsistent with the examples, as long as it is recognizably equivalent Responses will not earn the point if they • guard the return with incorrect logic 1 point 8 Calls substring and length (or equivalent) on String objects Responses can still earn the point even if they • calculate substring parameter values incorrectly • call substring and/or length from a method other than getLines • use a method name inconsistent with the examples, as long as it is recognizably equivalent Responses will not earn the point if they • fail to call substring or length on String objects • call substring or length with an incorrect number of parameters, with a parameter of an incorrect type, or with incorrectly ordered parameters, anywhere in the class 1 point 9 getLines constructs the delimited sign output appropriately (algorithm) Responses can still earn the point even if they • call substring and/or length incorrectly • fail to return the constructed String (return not assessed) • handle the empty string /null case incorrectly • construct the output in the constructor • use a method name inconsistent with the examples, as long as it is recognizably equivalent 1 point AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Responses will not earn the point if they • end the constructed output with a ; or extraneous spaces • modify the contents of message or width after they have been initialized (no additional –1y penalty) Question-specific penalties None Total for question 2 9 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Alternate canonical: public class Sign { private int numLines; private String lines; public Sign(String msg, int width) { if (!msg.equals("")) { lines = ""; while (msg.length() > width) { lines += msg.substring(0, width) + ";"; msg = msg.substring(width); numLines++; } lines += msg; numLines++; } } public int numberOfLines() { return numLines; } public String getLines() { return lines; } } AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Applying the Scoring Criteria Apply the question scoring criteria first, which always takes precedence. Penalty points can only be deducted in a part of the question that has earned credit via the question rubric. No part of a question (a, b, c) may have a negative point total. A given penalty can be assessed only once for a question, even if it occurs multiple times or in multiple parts of that question. A maximum of 3 penalty points may be assessed per question. 1-Point Penalty v) Array/collection access confusion ([] get) w) Extraneous code that causes side-effect (e.g., printing to output, incorrect precondition check) x) Local variables used but none declared y) Destruction of persistent data (e.g., changing value referenced by parameter) z) Void method or constructor that returns a value No Penalty • Extraneous code with no side-effect (e.g., valid precondition check, no-op) • Spelling/case discrepancies where there is no ambiguity* • Local variable not declared provided other variables are declared in some part • private or public qualifier on a local variable • Missing public qualifier on class or constructor header • Keyword used as an identifier • Common mathematical symbols used for operators (× • ÷ ≤ ≥ <> ≠) • [] vs. () vs. <> • = instead of == and vice versa • length/size confusion for array, String, List, or ArrayList; with or without ( ) • Extraneous [] when referencing entire array • [i,j] instead of [i][j] • Extraneous size in array declaration, e.g., int[size] nums = new int[size]; • Missing ; where structure clearly conveys intent • Missing { } where indentation clearly conveys intent • Missing ( ) on parameter-less method or constructor invocations • Missing ( ) around if or while conditions *Spelling and case discrepancies for identifiers fall under the “No Penalty” category only if the correction can be unambiguously inferred from context, for example, “ArayList” instead of “ArrayList”. As a counterexample, note that if the code declares "int G=99, g=0;", then uses "while (G < 10)" instead of "while (g < 10)", the context does not allow for the reader to assume the use of the lower case variable. AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Question 3: Array / ArrayList 9 points Canonical solution (a) public void cleanData(double lower, double upper) { for (int i = temperatures.size() – 1; i >= 0; i--) { double temp = temperatures.get(i); if (temp < lower || temp > upper) { temperatures.remove(i); } } } 4 points (b) public int longestHeatWave(double threshold) { int waveLength = 0; int maxWaveLength = 0; for (double temp : temperatures) { if (temp > threshold) { waveLength++; if (waveLength > maxWaveLength) { maxWaveLength = waveLength; } } else { waveLength = 0; } } return maxWaveLength; } 5 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board (a) cleanData Scoring Criteria Decision Rules 1 Traverses temperatures (no bounds errors) Responses can still earn the point even if they • do a forward traversal of the list • skip a value because removal from the list is handled incorrectly • use an enhanced for loop, as long as the list element is used in the body of the loop Responses will not earn the point if they • fail to ever access an element of temperatures in the loop • access the elements of temperatures incorrectly 1 point 2 Determines whether an element of temperature list should be removed, using lower and upper Responses can still earn the point even if they • access elements of temperature list incorrectly Responses will not earn the point if they • apply incorrect comparison (< vs <=) or logic (|| vs &&) to identify elements of list for removal 1 point 3 Calls remove (or equivalent) on temperature list with an appropriate parameter Responses can still earn the point even if they • add the element to a new ArrayList that is not declared, is declared incorrectly, or is not assigned to the instance variable, as long as the order of elements is maintained Responses will not earn the point if they • call remove or add incorrectly 1 point 4 Removes all and only identified elements of temperature list (algorithm) Responses can still earn the point even if they • call remove incorrectly • access the elements of temperature list incorrectly Responses will not earn the point if they • add elements to a new ArrayList that is not declared, is declared incorrectly, or is not assigned to the instance variable • skip a temperature list element in the traversal because removal is not handled correctly 1 point Total for part (a) 4 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board (b) longestHeatWave Scoring Criteria Decision Rules 5 Traverses temperatures (no bounds errors) Responses will not earn the point if they • fail to access an element of temperatures in the loop • access the elements of temperatures incorrectly 1 point 6 Compares an element of temperature list to threshold (in the context of a loop) Responses can still earn the point even if they • always compare threshold to the same list element Responses will not earn the point if they • apply incorrect comparison (> vs >=) to identify heat wave days 1 point 7 Initializes and increments the length of a heat wave (in the context of a loop or condition) Responses can still earn the point even if they • fail to reset the length of the current heat wave when the heat wave ends 1 point 8 Determines the length of at least one heat wave (algorithm) Responses will not earn the point if they • fail to reset the length of the current heat wave when the heat wave ends 1 point 9 Identifies the longest heat wave and returns its length (algorithm) 1 point Total for part (b) 5 points Question-specific penalties None Total for question 3 9 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Applying the Scoring Criteria Apply the question scoring criteria first, which always takes precedence. Penalty points can only be deducted in a part of the question that has earned credit via the question rubric. No part of a question (a, b, c) may have a negative point total. A given penalty can be assessed only once for a question, even if it occurs multiple times or in multiple parts of that question. A maximum of 3 penalty points may be assessed per question. 1-Point Penalty v) Array/collection access confusion ([] get) w) Extraneous code that causes side-effect (e.g., printing to output, incorrect precondition check) x) Local variables used but none declared y) Destruction of persistent data (e.g., changing value referenced by parameter) z) Void method or constructor that returns a value No Penalty • Extraneous code with no side-effect (e.g., valid precondition check, no-op) • Spelling/case discrepancies where there is no ambiguity* • Local variable not declared provided other variables are declared in some part • private or public qualifier on a local variable • Missing public qualifier on class or constructor header • Keyword used as an identifier • Common mathematical symbols used for operators (× • ÷ ≤ ≥ <> ≠) • [] vs. () vs. <> • = instead of == and vice versa • length/size confusion for array, String, List, or ArrayList; with or without ( ) • Extraneous [] when referencing entire array • [i,j] instead of [i][j] • Extraneous size in array declaration, e.g., int[size] nums = new int[size]; • Missing ; where structure clearly conveys intent • Missing { } where indentation clearly conveys intent • Missing ( ) on parameter-less method or constructor invocations • Missing ( ) around if or while conditions *Spelling and case discrepancies for identifiers fall under the “No Penalty” category only if the correction can be unambiguously inferred from context, for example, “ArayList” instead of “ArrayList”. As a counterexample, note that if the code declares "int G=99, g=0;", then uses "while (G < 10)" instead of "while (g < 10)", the context does not allow for the reader to assume the use of the lower case variable. AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board Question 4: 2D Arrays 9 points Canonical solution (a) public boolean moveCandyToFirstRow(int col) { if (box[0][col] != null) { return true; } for (int row = 1; row < box.length; row++) { if (box[row][col] != null) { box[0][col] = box[row][col]; box[row][col] = null; return true; } } return false; } 4 points (b) public Candy removeNextByFlavor(String flavor) { for (int row = box.length - 1; row >= 0; row--) { for (int col = 0; col < box[0].length; col++) { if (box[row][col] != null && box[row][col].getFlavor().equals(flavor)) { Candy taken = box[row][col]; box[row][col] = null; return taken; } } } return null; } 5 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board (a) moveCandyToFirstRow Scoring Criteria Decision Rules 1 Accesses all necessary elements of column col of box (no bounds errors) Responses can still earn the point even if they • return early, as long as the loop bounds are appropriate Responses will not earn the point if they • fail to access an element of box in the loop • access the elements of box incorrectly 1 point 2 Compares candy box element at row 0 and column col to null Responses can still earn the point even if they • make the comparison inside the loop or at some incorrect point in the code Responses will not earn the point if they • fail to use != or equivalent 1 point 3 Identifies and moves appropriate Candy object to first row if necessary (algorithm) Responses can still earn the point even if they • return early, as long as the identify-andmove are inside a loop and would work if the loop got that far Responses will not earn the point if they • fail to replace the moved Candy object with null • move or swap objects when the first row is already occupied 1 point 4 Returns true when non-empty square is identified and false if non-empty square is not identified in the context of a loop (algorithm) Responses can still earn the point even if they • fail to replace the moved Candy object with null • incorrectly identify a non-empty square Responses will not earn the point if they • return early 1 point Total for part (a) 4 points AP® Computer Science A 2023 Scoring Guidelines © 2023 College Board (b) removeNextByFlavor Scoring Criteria Decision Rules 5 Traverses box in specified order (bottom to top, left to right) (no bounds errors) Responses will not earn the point if they • fail to access an element of box in the loop • access the elements of box incorrectly 1 point 6 Guards against a method call on a null element of the candy box (in the context of an if statement) Responses will not earn the point if they • fail to use != or equivalent 1 point 7 Calls getFlavor on a Candy object Responses can still earn the point even if they • access the element of the candy box incorrectly • call getFlavor on the incorrect Candy object Responses will not earn the point if they • call getFlavor on an object of a different type or on the Candy class • attempt to create a Candy object • include parameters 1 point 8 Compares a Candy object’s flavor with flavor parameter Responses will not earn the point if they • fail to use equals 1 point 9 Replaces first matching Candy object with null and returns replaced object (algorithm) Responses can still earn the point even if they • access elements of the candy box incorrectly • call getFlavor incorrectly or on a null Candy object • compare a Candy object’s flavor to the parameter using == Responses will not earn the point if they • fail to replace the identified object within the 2D array with null before returning • fail to return null when no matching Candy object is found • set multiple elements to null 1 point Total for part (b) 5 points Question-specific penalties None Total for question 4 9 points'''
CRITERIA = [
{
'req': '''1 Loops over necessary minutes in an hour Responses can still earn the point even if they • loop over fewer than 60 minutes as long as at least (60 – duration + 1) minutes are included • loop over 60 minutes and use a boolean to indicate that a free block has been found 1 point''',
'part': 'a',
},
{
'req': '''2 Calls isMinuteFree with period and another int parameter Responses can still earn the point even if they • call isMinuteFree with invalid parameters due to incorrect loop bounds Responses will not earn the point if they • use incorrect parameter types • order the parameters incorrectly • call the method on the class or on an object other than this (use of this is optional) 1 point''',
'part': 'a',
},
{
'req': '''3 Keeps track of contiguous free minutes in a block (algorithm) Responses can still earn the point even if they • call isMinuteFree incorrectly Responses will not earn the point if they • fail to reset when a nonfree minute is found • call isMinuteFree with minutes >= 60 1 point''',
'part': 'a',
},
{
'req': '''4 Checks whether a valid block of duration minutes has been found Responses can still earn the point even if they • maintain a boolean instead of accumulating the block length 1 point''',
'part': 'a',
},
{
'req': '''5 Calculates and returns starting minute and -1 appropriately based on identified block (algorithm) Responses will not earn the point if they • are off by one on the returned value 1 point''',
'part': 'a',
},
{
'req': '''6 Loops over periods from startPeriod through endPeriod (no bounds errors) 1 point''',
'part': 'b',
},
{
'req': '''7 Calls findFreeBlock and reserveBlock with correct number of int parameters, representing a period and minute as appropriate, and duration Responses can still earn the point even if they • use incorrect parameter values Responses will not earn the point if they • use incorrect parameter types • order the parameters incorrectly • call the methods on the class or on an object other than this (use of this is optional) 1 point''',
'part': 'b',
},
{
'req': '''8 Guards call to method to reserve a block by determining that starting minute is not -1 1 point''',
'part': 'b',
},
{
'req': '''9 Books correct appointment and returns appropriate boolean (algorithm) Responses can still earn the point even if they • have incorrect bounds in the loop • call findFreeBlock or reserveBlock incorrectly Responses will not earn the point if they • fail to return true or false • return before the call to reserveBlock 1 point''',
'part': 'b',
},
]