📖 Quick Study Guide: Functions & Area Calculation in AP CS
🧠 Practice Quiz: Functions for Area Calculation
1. Which of the following is the primary benefit of using functions (methods) in AP Computer Science for tasks like calculating area?- A) It makes the code run faster.
- B) It allows for code reusability and modularity.
- C) It automatically handles error checking.
- D) It reduces the total memory usage of the program.
2. Consider a function designed to calculate the area of a rectangle. What would be the most appropriate return type for this function if the dimensions are integers?- A) `void`
- B) `int`
- C) `String`
- D) `double`
3. A function `public static double calculateCircleArea(double radius)` is defined. Which of the following is an example of a valid call to this function?- A) `calculateCircleArea(5);`
- B) `double area = calculateCircleArea("five");`
- C) `System.out.println(calculateCircleArea());`
- D) `calculateCircleArea(double r);`
4. What does the `void` keyword signify as a return type for a function in Java?- A) The function returns an integer value.
- B) The function returns no value.
- C) The function can accept any type of parameter.
- D) The function is not yet implemented.
5. Which of the following function signatures is best suited for calculating the area of a triangle, given its base and height?- A) `public static void triangleArea(double base, double height)`
- B) `public static double triangleArea(double base, double height)`
- C) `public static int triangleArea(String base, String height)`
- D) `public static double triangleArea()`
6. If a function `calculateSquareArea(side)` is called with `calculateSquareArea(7.5)`, what is the likely type of the `side` parameter?- A) `int`
- B) `String`
- C) `double`
- D) `boolean`
7. Which mathematical constant is typically used when calculating the area of a circle in Java, often found in the `Math` class?- A) `Math.E`
- B) `Math.PI`
- C) `Math.SQRT2`
- D) `Math.abs`
Click to see Answers
1. B
2. D
3. A
4. B
5. B
6. C
7. B