Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections FRQ

Work through AP Computer Science A free-response questions on Data Collections, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Subtopic: Arraylists Clear filter

Questions 31–40 of 52
  1. 31
  2. 32
  3. 33
  4. 34
  5. 35
  6. 36
  7. 37
  8. 38
  9. 39
  10. 40

Question 31

Free response Arraylists
UniqueWordAnalyzer processes nonempty lowercase comments. Words are separated by single spaces; each comment contains at least one word. public class…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 32

Free response Arraylists
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…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 33

Free response Arraylists
Shipment stores destination, weight in kilograms and fragile status. ShipmentTracker maintains an ArrayList . Do not use Map or HashMap for grouping. public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 34

Free response Arraylists
The ItemInfo class is used to store information about an item at a store. A partial declaration of the ItemInfo class is shown. public class ItemInfo { /** *…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 35

Free response Arraylists
A tournament round pairs best-ranked competitors with worst-ranked competitors. Implement the Round constructor and buildMatches. Names are ordered from best to…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 36

Free response Arraylists
GPSRouter stores routes in an initialized ArrayList routes. Route provides String getName(), int getMiles(), and void setMiles(int num). The provided…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 37

Free response Arraylists
Consider the following incomplete class definition for a grade book: public class StudentGradeBook { private ArrayList<Integer> grades; // values 0-100 public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 38

Free response Arraylists
A sensor produces a stream of numeric readings. Consider the following incomplete class: public class SensorLog { private ArrayList<Double> readings; public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 39

Free response Arraylists
The Arctic Research Station Polaris-7 collects hourly temperature readings from its sensor array. Scientists store these readings in an ArrayList<Double> and…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 40

Free response Arraylists

An online community platform stores user posts as strings in an ArrayList. The moderation team needs tools to clean up duplicate content and identify trending topics. You are writing two analysis methods for the MessageBoard class.

PART A

Write the method public ArrayList<String> removeDuplicates(ArrayList<String> posts) that returns a new ArrayList containing only the first occurrence of each unique string, in original order.

For example, if posts is ["hello", "world", "hello", "java", "world", "hello"], the method returns ["hello", "world", "java"].

public ArrayList<String> removeDuplicates(ArrayList<String> posts) {

PART B

Write the method public String mostFrequent(ArrayList<String> posts) that returns the string appearing most often. If there is a tie, return the one that appears first in the list.

For example, if posts is ["cat", "dog", "cat", "bird", "dog", "cat"], the method returns "cat" (appears 3 times).

public String mostFrequent(ArrayList<String> posts) {
The answer and the full solution open in a window.
Question 31 of 52
Page 4 of 6