AP Computer Science A Free-Response
Question 1: Primitive Types vs Reference Types (Unit 1)
Situation: You are developing a banking application where you need to represent customer information. You have decided to use both primitive types and reference types for this purpose.
(a) Define primitive types and reference types in Java. Provide examples of each.
(b) Explain the differences between primitive types and reference types in terms of memory allocation and usage in Java programs.
(c) Code:
You have a method calculateInterest
that takes a primitive double
type representing the principal amount and a reference type Customer
representing the customer information. Write the method signature and the method implementation. Include comments to explain your code.
Question 2: Iteration over 2D arrays (Unit 4)
Situation: You are developing a game where you need to track player scores on a 2D grid representing levels and attempts.
(a) Explain the concept of iteration over a 2D array in Java. Provide an example scenario where iterating over a 2D array is useful in a programming task.
(b) Code:
You need to implement a method calculateTotalScore
that takes a 2D array scores
of integers representing player scores and returns the sum of all the elements in the array. Write the method signature and the method implementation. Include comments to explain your code.
Question 3: Array (Unit 6)
Situation: You are developing a student management system where you need to store and analyze the grades of students in a class.
(a) Define an array in Java. Explain its significance and usefulness in programming.
(b) Code:
You need to implement a method calculateAverageGrade
that takes an array grades
of integers representing student grades and returns the average of all the elements in the array. Write the method signature and the method implementation. Include comments to explain your code.
Question 4: Math Class (Unit 2)
Situation: You are developing a scientific calculator application where users need to perform various mathematical operations.
(a) Discuss the purpose and utility of the Math class in Java programming. Provide examples of at least three methods provided by the Math class and explain their usage.
(b) Code:
You need to implement a method calculateSquareRoot
that takes a double
number as input and returns its square root using the Math class. Write the method signature and the method implementation. Include comments to explain your code.
Question 5: If, While, Else (Unit 3-4)
Situation: You are developing a simple grading system where you need to determine if a given score is passing or failing.
(a) Explain the roles and usage of the if statement, while loop, and else statement in Java programming. Provide examples illustrating each.
(b) Code:
You need to implement a method printGradeStatus
that takes an integer score
as input and prints “Pass” if the score is greater than or equal to 60, and “Fail” otherwise. Write the method signature and the method implementation. Include comments to explain your code.
AP Computer Science A Free-Response Question Grading Rubric
Each question is out of 5 points total
Question 1: Primitive Types vs Reference Types
(a) Definition and Examples:
- 1 point: Correctly defines primitive types and reference types with accurate examples. (b) Definition and Examples:
- 1 point: Provides a clear explanation of the differences between primitive types and reference types, including memory allocation and usage.
(c) Code Implementation:
- Method Signature: 1 point
- Method Implementation: 2 points
- Comments: 1 point
Question 2: Iteration over 2D Arrays
(a) Explanation and Scenario:
- 1 point: Provides a clear explanation of iteration over 2D arrays and presents a relevant scenario.
(b) Code Implementation:
- Method Signature: 1 point
- Method Implementation: 2 points
- Comments: 1 point
Question 3: Array
(a) Definition and Significance:
- 1 point: Clearly defines an array and explains its significance in programming.
(b) Code Implementation:
- Method Signature: 1 point
- Method Implementation: 2 points
- Comments: 1 point
Question 4: Math Class
(a) Purpose and Examples:
- 1 point: Discusses the purpose and utility of the Math class and provides accurate examples of methods.
(b) Code Implementation:
- Method Signature: 1 point
- Method Implementation: 2 points
- Comments: 1 point
Question 5: If, While, Else
(a) Explanation and Examples:
- 1 point: Clearly explains the roles and usage of if statements, while loops, and else statements with accurate examples.
(b) Code Implementation:
- Method Signature: 1 point
- Method Implementation: 2 points
- Comments: 1 point