Skip to main content
Logo image

Section 15.5 FRQ 1B - Strings - Part 2

From the 2025 Course and Exam Description:
Free-Response Question 1: Methods and Control Structures. Students will write two methods or one constructor and one method of a given class based on the provided specifications and examples. In Part A (4 points), the method or constructor will require students to write iterative or conditional statements, or both, as well as statements that call methods in the specified class.
In Part B (3 points), the method or constructor will require calling String methods.
FRQ 1B requires the following skills:
Teacher Insights
  • You do not need to include import statements. You can assume that any standard Java class is already imported.
  • You will NEVER print. If you think you need to print, you probably need to return something.
  • You will NOT need to write a main.

Subsection 15.5.1 String Algorithms

There are many algorithms that traverse or process Strings that use loops and conditional statements.
Common algorithms include:
  • Counting the number of substrings that meet specific criteria
  • Determining if one or more substrings has a specific property
  • Building a new String based on certain conditions

Subsection 15.5.2 Processing a String with a For Loop

Many algorithms can be solved with the accumulator pattern, similar to FRQ1A. In some cases, the accumulator value will be a String.
There are four steps to the accumulator pattern:
  • initialize the accumulator variable before the loop
  • loop through the letters of the String
  • update the accumulator variable inside the loop
  • return the accumulated value (if necessary)

Subsection 15.5.3 String Algorithm - Count Vowels

Activity 15.5.1.

You are working on a text-analysis tool. The StringProcessor class contains a helper method, isVowel(String letter), which returns true if a single-character string is a vowel (A, E, I, O, U, case-insensitive) and false otherwise.
Write the countVowels method. This method analyzes a given String and returns the total number of vowels present in that string.

Subsection 15.5.4 String Algorithm - Make Abbreviation

Activity 15.5.2.

Write a method called makeAbbreviation that takes a multi-word String and returns a new String consisting of the first letter of each word in uppercase.

Subsection 15.5.5 String Algorithm - Mask Vowels

Activity 15.5.3.

Write a method called maskVowels that takes a String and returns a new String where all vowels are replaced with asterisks (*), but only if the String is longer than 3 letters.

Subsection 15.5.6 String Algorithm - Count Occurrences

Activity 15.5.4.

Write a method called countOccurrences that determines how many times a specific target string appears within a larger text string.
Be careful! It is easy to end up with an infinite loop if you are not careful when updating your loop variable. You will need to use the indexOf method to find the next occurrence of the target string, and then update your loop variable to start searching for the next occurrence after the current one.
You have attempted of activities on this page.