FRQ workshop: the 4 question types · 自由作答攻略:四种题型
The free-response section
- The AP CSA exam has two parts. Part 1 is multiple choice. Part 2 is free response (you write Java by hand).
- There are always 4 free-response questions (FRQs), and they come in the same 4 types every year.
- This lesson is a quick map of the 4 types. Knowing the pattern makes the exam much less scary. You can do this!
自由作答部分
- AP CSA 考试有两个部分。第一部分是选择题。第二部分是自由作答(free response,你手写 Java)。
- 这部分总是有 4 道自由作答题(FRQ),而且每年都是同样的 4 种类型。
- 这一课是这 4 种类型的快速地图。了解套路会让考试不再可怕。你能做到的!
Type 1: Methods and Control Structures
- You write one or two methods using loops,
if, and simple math onint,double,boolean, andString. - No class to design — the class is given. You just fill in the method body.
- This is the most "plain coding" question. Lessons 1–8 cover everything you need.
类型 1:方法与控制结构
- 你要写一到两个方法,用到循环、
if,以及对int、double、boolean、String的简单运算。 - 不用设计类 —— 类已经给好了。你只要填上方法体。
- 这是最"纯写代码"的题目。第 1–8 课覆盖了你需要的一切。
public class Grades {
// Count the scores that are 60 or more.
public static int countPassing(int[] scores) {
int count = 0;
for (int s : scores) {
if (s >= 60) {
count = count + 1;
}
}
return count;
}
public static void main(String[] args) {
int[] scores = {72, 40, 95, 60, 33};
System.out.println(countPassing(scores)); // 3
}
}
Type 2: Class Design
- You are given a description of a class and must write the whole class.
- That means: instance variables, a constructor, and the methods they ask for.
- Remember
privatefields, the constructor with the same name as the class, andthis.field = field. Lesson 6 covers this.
类型 2:类的设计
- 题目给你一段类的描述,你必须写出整个类。
- 也就是说:实例变量、一个构造方法(constructor),以及他们要求的那些方法。
- 记住用
private字段、构造方法要和类同名、以及this.field = field。第 6 课覆盖了这些。
public class Student {
private String name;
private int score;
public Student(String name, int score) {
this.name = name;
this.score = score;
}
public int getScore() {
return score;
}
}
Type 3: Array / ArrayList
- You work with an
ArrayList(or sometimes an array) and write code that traverses it. - Common jobs: find a value, count items, remove items, or build a new list.
- Watch the index carefully when you remove while looping. Lessons 9–11 cover this.
类型 3:数组 / ArrayList
- 你要处理一个
ArrayList(有时是数组),并写出遍历(traverse)它的代码。 - 常见任务:找一个值、数个数、删除元素,或者建一个新列表。
- 在循环里删除元素时要小心下标。第 9–11 课覆盖了这些。
// Count the Strings longer than 3 letters.
int count = 0;
for (int i = 0; i < words.size(); i++) {
if (words.get(i).length() > 3) {
count++;
}
}
return count;
Type 4: 2-D Array
- You work with a 2-D array (a grid of rows and columns).
- You use nested loops: an outer loop for rows, an inner loop for columns.
- Common jobs: sum a row, sum a column, find the largest value, or count matches. Lesson 12 covers this.
类型 4:二维数组
- 你要处理一个二维数组(一个由行和列组成的网格)。
- 你要用嵌套循环:外层循环走行,内层循环走列。
- 常见任务:对一行求和、对一列求和、找最大值,或者数匹配的个数。第 12 课覆盖了这些。
// Add up every value in the grid.
int total = 0;
for (int r = 0; r < grid.length; r++) {
for (int c = 0; c < grid[r].length; c++) {
total += grid[r][c];
}
}
return total;
Exam strategy: read carefully
- Read the whole question first. Underline what the method must return and what its parameters are.
- Look at the example table they give. It shows exactly what your code should produce.
- Copy the method header they give you. Do not change its name, parameters, or return type.
考试策略:仔细读题
- 先把整道题读完。 划出方法必须返回什么,以及它的参数是什么。
- 看他们给的例子表格。它准确地告诉你代码应该产生什么结果。
- 抄下他们给你的方法头(method header)。不要改它的名字、参数或返回类型。
Exam strategy: write methods that work
- Write the base of a loop first, then fill in the body. Get it running in your head step by step.
- Traverse correctly: start the index at
0, stop atlength(orsize()); check the edges. - Use
returnwith the right type. If the header saysint, return anint.
考试策略:写出能用的方法
- 先写出循环的框架,再填里面的内容。在脑子里一步一步把它跑通。
- 正确地遍历:下标从
0开始,在length(或size())处停止;检查两端的边界。 - 用
return返回正确的类型。如果方法头写的是int,就返回一个int。
Exam strategy: small wins add up
- You get points for parts that work, even if the whole method is not perfect. Always write something.
- Use only Java you know from this course. Simple, correct code beats clever code.
- Check your work with the example values from the question before you move on.
考试策略:小分也能累积
- 即使整个方法不完美,能用的部分也会得分。一定要写出一些东西。
- 只用这门课里你学过的 Java。简单、正确的代码胜过花哨的代码。
- 继续下一题之前,用题目里的例子数值检查一下你的答案。
You are ready
- The 4 types never change: methods, class design, array/ArrayList, and 2-D array.
- Every skill you need for these four FRQ types is in lessons 1–12. Practice each type a few times and the pattern becomes familiar.
- Stay calm, read carefully, and write the code you know. Good luck on the exam!
你准备好了
- 这 4 种类型从不改变:方法、类的设计、数组/ArrayList、二维数组。
- 这四种题型需要的每一项技能都在第 1–12 课里。每种类型多练几次,套路就会变得熟悉。
- 保持冷静,仔细读题,写出你会的代码。祝你考试顺利!
Common mistakes
- Match the method header exactly: the return type and the parameters.
- Read the whole prompt before you start coding.
常见错误
- 方法头要完全对上:返回类型和参数。
- 开始写之前先读完整个题目。
Now you try
- Try one FRQ-style method yourself — the same shape as Type 1 above.
- Press Check answer to compile and run it on the server.
现在轮到你
- 自己写一个 FRQ 风格的方法 —— 和上面第一类题型的结构一样。
- 按检查答案在服务器上编译并运行它。
FRQ practice — Type 1 (Methods). Complete countAtLeast(int[] scores, int limit) so it returns how many values in scores are at least limit (greater than or equal). Use a loop and an if, like the worked example above. · FRQ 练习 —— 第一类(方法)。完成 countAtLeast(int[] scores, int limit),返回 scores 中有多少个值至少为 limit(大于或等于)。像上面的范例那样,用一个循环和一个 if。
Click Run to see the output here. · 点击“运行”查看此处输出。
FRQ practice — Type 2 (Class design). Complete the Rectangle class: store width and height from the constructor, and finish area() so it returns width × height. This is exactly what a Type 2 FRQ asks for. · FRQ 练习 —— 第二类(类设计)。完成 Rectangle 类:把构造函数传入的 width 和 height 存起来,并完成 area(),让它返回宽 × 高。这正是第二类 FRQ 所要求的。
Click Run to see the output here. · 点击“运行”查看此处输出。