CSA 2019 CED FRQs Quesonly PDF
CSA 2019 CED FRQs Quesonly PDF
Scoring Guidelines
Question 1: Methods and Control Structures
This question involves the use of check digits, which can be used to help detect if an error has occurred when a number
is entered or transmitted electronically. An algorithm for computing a check digit, based on the digits of a number, is
provided in part (a).
The CheckDigit class is shown below. You will write two methods of the CheckDigit class.
*/
public static int getCheck(int num)
{
{
/* to be implemented in part (b) */
}
Return
Method Call Value Explanation
getNumberOfDigits(283415) 6 The number 283415 has 6 digits.
getDigit(283415, 1) 2 The first digit of 283415 is 2.
getDigit(283415, 5) 1 The fifth digit of 283415 is 1.
Complete the getCheck method below. You must use getNumberOfDigits and getDigit appropriately to
receive full credit.
/** Returns the check digit for num, as described in part (a).
* Precondition: The number of digits in num is between one and six,
* inclusive.
* num >= 0
*/
Return
Method Call Value Explanation
getCheck(159) 2 The check digit for 159 is 2.
The number 1592 is a valid combination of a
isValid(1592) true
number (159) and its check digit (2).
The number 1593 is not a valid combination of a
isValid(1593) false number (159) and its check digit (3) because 2 is
the check digit for 159.
Complete method isValid below. Assume that getCheck works as specified, regardless of what you wrote in
part (a). You must use getCheck appropriately to receive full credit.
/** Returns true if numWithCheckDigit is valid, or false
* otherwise, as described in part (b).
* Precondition: The number of digits in numWithCheckDigit is
* between two and seven, inclusive.
* numWithCheckDigit >= 0
*/
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)
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.
The Gizmo class represents gadgets that people purchase. Some Gizmo objects are electronic and others are
not. A partial definition of the Gizmo class is shown below.
* otherwise.
*/
The OnlinePurchaseManager class manages a sequence of Gizmo objects that an individual has purchased from
an online vendor. You will write two methods of the OnlinePurchaseManager class. A partial definition of the
OnlinePurchaseManager class is shown below.
/** Returns the number of purchased Gizmo objects that are electronic
* whose manufacturer is maker, as described in part (a).
*/
(a) Write the countElectronicsByMaker method. The method examines the ArrayList instance variable
purchases to determine how many Gizmo objects purchased are electronic and are manufactured by maker.
Assume that the OnlinePurchaseManager object opm has been declared and initialized so that the
ArrayList purchases contains Gizmo objects as represented in the following table.
Index in purchases 0 1 2 3 4 5
Value returned
by method call true false true false true false
isElectronic()
Value returned
by method call "ABC" "ABC" "XYZ" "lmnop" "ABC" "ABC"
getMaker()
(b) When purchasing items online, users occasionally purchase two identical items in rapid succession without intending
to do so (e.g., by clicking a purchase button twice). A vendor may want to check a user’s purchase history to detect such
occurrences and request confirmation.
Write the hasAdjacentEqualPair method. The method detects whether two adjacent Gizmo objects in
purchases are equivalent, using the equals method of the Gizmo class. If an adjacent equivalent pair is found,
the hasAdjacentEqualPair method returns true. If no such pair is found, or if purchases has fewer than
two elements, the method returns false.