Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

victoria checkStyle #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion src/main/java/org/translation/JSONDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public static void main(String[] args) {
*/
public static String getKeyOneOfSecond(JSONArray jsonArray) {
// TODO: Complete this method.
return "";
JSONObject second = jsonArray.getJSONObject(1);
return second.getString("key1");
}

}
15 changes: 13 additions & 2 deletions src/main/java/org/translation/JSONTranslationExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public JSONTranslationExample() {
public String getCanadaCountryNameSpanishTranslation() {

// TODO Checkstyle: '30' is a magic number.
JSONObject canada = jsonArray.getJSONObject(30);
JSONObject canada = jsonArray.getJSONObject(CANADA_INDEX);
return canada.getString("es");
}

Expand All @@ -52,7 +52,18 @@ public String getCanadaCountryNameSpanishTranslation() {
* @return the translation of country to the given language or "Country not found" if there is no translation.
*/
public String getCountryNameTranslation(String countryCode, String languageCode) {
return "Country not found";
int id = 0;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);

if (countryCode.equals(jsonObject.getString("alpha3"))) {
id = i;
break;
}
}
JSONObject country = jsonArray.getJSONObject(id);
return country.getString(languageCode);
// return "Country not found";
}

/**
Expand Down