CS173: Intro to Computer Science - Strings Revisited (3 Points)

Developed by Professor Tralie and Professor Mongan.

Exercise Goals

The goals of this exercise are:
  1. To iterate over String variables and return part-way through the string iteration.
Implement the program below that converts a String to "Pig Latin" according to the rules at the bottom of the page.
Welcome to our online modules system! Be sure to log in with your Urinus ID before you proceed. For example, Professor Tralie's ID is ctralie. If you are not an Ursinus student, that's fine! Just make something up, and you can still run everything

                    



Rules

We will simplify the rules as follows:

  • If a String starts with a vowel, simply append “yay” to the end of the String.
  • Otherwise, modify the string so that all the letters of the String up to (but not including) the first vowel are moved to the end of the String. Then, append “ay” to the end of the resulting String.

Hints

Given a String variable (let’s say it’s called str):

  • You can use the str.substring(i) method to return a String containing all characters in str from position i to the end of the String. Don’t forget that String indices are numbered starting from 0.
  • You can use the str.substring(i, j) method to return a String containing all characters in str from position i up to (but not including) position j of the String.
  • You can use the + operator to concatenate two String values (or their substrings, which are also just String values!).