Question 3: Data Analysis with ArrayList
Keeping a to-do list in priority order
- Unit 4
- 5 points
- About 18 minutes
You write one method that traverses, analyzes or changes data stored in an ArrayList of objects, using the classes described in the question. New since the course was revised for 2025–26 (first tested in May 2026): it's always an ArrayList now (it used to be an array or an ArrayList), it's worth 5 points instead of 9, and points are no longer taken off as penalties. On the exam: Question 3 of 4, 5 points. Section II has 4 free-response questions in 90 minutes (45% of the score), all assessing Practice 2 (Develop Code). The exam is fully digital in Bluebook: you type your Java, and the Java Quick Reference is provided. No calculator. Suggested time is our split of the 90 minutes by points; College Board gives no per-question timing.
The question and its sources
A to-do app stores tasks. Each task has a name and a priority, where a higher number means a more urgent task. The TaskList class keeps the tasks in an ArrayList sorted from highest priority to lowest. Tasks with the same priority are kept in the order they were added.
The Task class
public class Task
{
/** Returns the name of the task */
public String getName()
{ /* implementation not shown */ }
/** Returns the priority of the task, an integer from 0 to 10 */
public int getPriority()
{ /* implementation not shown */ }
// There may be instance variables, constructors, and methods that are not shown.
}The TaskList class
public class TaskList
{
/**
* The tasks, sorted from highest to lowest priority; tasks with
* equal priority are in the order they were added.
* Contains no null elements; may be empty.
*/
private ArrayList<Task> tasks;
/**
* Inserts t into tasks so that tasks stays sorted as described.
* t goes after every task that has the same priority as t.
* Precondition: t is not null.
*/
public void addTask(Task t)
{ /* to be implemented */ }
// There may be instance variables, constructors, and methods that are not shown.
}Example: tasks before any calls, written as name/priority
| Index | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| Task | essay/5 | lab/3 | email/3 | laundry/1 |
Source: Hypothetical example
Example calls, made one after another
| Call | Where the new task goes | tasks afterward |
|---|---|---|
addTask(quiz/3) | Index 3, after email/3 | essay/5, lab/3, email/3, quiz/3, laundry/1 |
addTask(form/9) | Index 0 | form/9, essay/5, lab/3, email/3, quiz/3, laundry/1 |
addTask(game/0) | The end | form/9, essay/5, lab/3, email/3, quiz/3, laundry/1, game/0 |
Source: Hypothetical example
Suggested time: 18 minutes
Your answers are saved in this browser as you type.
Part (a)
5 pointsWrite the TaskList method addTask, as described above. If tasks is empty, t becomes its only element.
Complete method addTask.public void addTask(Task t)
Tab indents. Press Esc, then Tab, to move on.
0 lines · 0 / 2,500 characters
Checking scoring…
Scoring it yourself shows you the rubric, examples and a model answer. Try writing your answer first.