Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 27 additions & 32 deletions src/main/java/org/translation/InLabByHandTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,32 @@
import java.util.ArrayList;
import java.util.List;

// TODO Task: modify this class so that it also supports the Spanish language code "es" and
// TOD Task: modify this class so that it also supports the Spanish language code "es" and
// one more language code of your choice. Each member of your group should add
// support for one additional langauge code on a branch; then push and create a pull request on GitHub.

// Extra Task: if your group has extra time, you can add support for another country code in this class.

/**
* An implementation of the Translator interface which translates
* the country code "can" to several languages.
* the country code COUNTRY_CANADA to several languages.
*/
public class InLabByHandTranslator implements Translator {
/**
* Returns the language abbreviations for all languages whose translations are
* available for the given country.
*
* @param country the country
* @return list of language abbreviations which are available for this country
*/

public static final String COUNTRY_CANADA = "can";

@Override

public List<String> getCountryLanguages(String country) {
// TODO Checkstyle: The String "can" appears 4 times in the file.
if ("can".equals(country)) {
return new ArrayList<>(List.of("de", "en", "zh"));

// TOD Checkstyle: The String COUNTRY_CANADA appears 4 times in the file.
if (COUNTRY_CANADA.equals(country)) {
return new ArrayList<>(List.of("de", "en", "zh", "es"));
}
return new ArrayList<>();
}

// TODO Checkstyle: Static variable definition in wrong order.
public static final String CANADA = "can";
// TOD Checkstyle: Static variable definition in wrong order.

/**
* Returns the country abbreviations for all countries whose translations are
Expand All @@ -41,34 +38,32 @@ public List<String> getCountryLanguages(String country) {
*/
@Override
public List<String> getCountries() {
return new ArrayList<>(List.of("can"));
return new ArrayList<>(List.of(COUNTRY_CANADA));
}

/**
* Returns the name of the country based on the specified country abbreviation and language abbreviation.
*
* @param country the country
* @param language the language
* @return the name of the country in the given language or null if no translation is available
*/
@Override

public String translate(String country, String language) {
// TODO Checkstyle: Return count is 5 (max allowed for non-void methods/ lambdas is 2).
// TODO Checkstyle: String literal expressions should be on the left side of an equals comparison
if (!country.equals("can")) {
/* 1️⃣ first (early-exit) return */
if (!COUNTRY_CANADA.equals(country)) {
return null;
}
if (language.equals("de")) {
return "Kanada";

/* 2️⃣ all remaining logic uses a single return */
String result = null;
if ("de".equals(language)) {
result = "Kanada";
}
else if (language.equals("en")) {
return "Canada";
else if ("en".equals(language)) {
result = "Canada";
}
else if ("zh".equals(language)) {
return "加拿大";
result = "加拿大";
}
else {
return null;
else if ("es".equals(language)) {
result = "Canadá";
}
return result;
}

}