Kotlinlearncs.online LogoJava
Return to List

Homework: String Name Occupation Parsing

Created By: Aisha Salau
/ Version: 2023.7.0

Write a method name parseNameOccupation that accepts a single non-null String in the following format:

  • "Aisha, a coder!"
  • "Felip, a doctor!"
  • "Gracie, a dog!"

Specifically, the input String has the following format: ", a !". (Gracie's one and only job is being a dog.) Note that the name will always be followed immediately by a comma, and the occupation by an exclamation point.

You should return a new String reformatted as follows: "My friend is a great !". So, given "Aisha, a coder!", you would return "My friend Aisha is a great coder!" Note that we have removed the comma but kept the exclamation point.

To complete this problem you will probably want to utilize the String methods split and substring.

Related Lessons

Stuck? You may find these lessons helpful: