Question: Implement a function addArticle (see code below) that takes a String as argument and returns a String. The input String is a country name in
Implement a function addArticle (see code below) that takes a String as argument and returns a String. The input String is a country name in French, and the output string should be the proper French article added in front of the country name.
(JAVA)
package edu.uab.cs203;
public class FrenchArticle { /// adds the appropriate article to the country /// e.g., "Etats-Unis" -> "les Etats-Unis" /// "Belize" -> "le Belize" /// "Allemagne" -> "l'Allemagne" /// "Grece" -> "la Grece" /// "Royaume-Uni" -> "le Royaume-Uni" /// @param country a valid country name without article /// @return article + country name private static String addArticle(String country) { /* * YOUR TASK: Implement this function * * Note (exercise P5.10): French country names are feminine when they end * with the letter 'e', masculine otherwise, except for the following * which are masculine even though they end with the letter 'e'. * le Belize * le Cambodge * le Mexique * le Mozambique * le Zaire * le Zimbabwe * * When the name starts with a vowel use l' as in * l'Allemagne, l'Autriche * * The following countries have plural names and use the article les * les Emirats-Arabes-Unis * les Etats-Unis * les Pays-Bas */
return ""; // TODO replace with proper return value
}
public static void main(String[] args)
{
String[] countries = new String[] { "Espagne", "Mexique", "Etats-Unis",
"Royaume-Uni", "Ecosse", "Bangladesh"};
for (String s : countries)
{
String withArticle = addArticle(s);
System.out.println(s + " -> " + withArticle);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
