Skip Top Navigation Bar

AP Computer Science A FRQ 1 Formatting Words

Formatting Words

This single part question is worth 3 points and could be paired with a distinct part a for FRQ #1.

AP CSA Alignment

Unit Alignment Learning Objectives Resources Skills
Unit 1: Using Methods and Objects 1.15.B Develop code to create string objects and determine the result of creating and combining strings. 2.C Write program code involving procedural abstractions.
Unit 2: Selection and Iteration 2.7.B Develop code to represent iterative processes using while loops and determine the result of these processes. 2.A Write program code to implement an algorithm.
2.8.A Develop code to represent iterative processes using for loops and determine the result of these processes.
2.10.A Develop code for standard and original algorithms that involve strings and determine the result of these algorithms.

A company needs to format words for display on a website. The rules for formatting are:

  • If a word contains more than one occurrence of the first vowel ('a', 'e', 'i', 'o', 'u', all lowercase), replace each occurrence after the first with an asterisk (*).

Write the method formatWord that takes a String parameter word and returns the formatted string as per the rules above.

Examples:

Input Output
"eager" "eag*r"
"outcome" "outc*me"
"mississippi" "miss*ss*pp*"
"chatbot" "chatbot"