Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

I can't pass this challenge, please help!

public static List<String> getPricesConvertedForArgentina(List<HousingRecord> records) { Locale argLocale = Locale.forLanguageTag("es-AR"); // This fluctuates and is hardcoded temporarily BigDecimal argPesoToUsdRate = new BigDecimal("15.48");

// TODO: These functions are in working order, but separately they don't match the single Function signature expected
Function<Integer, BigDecimal> usdToArgentinePesoConverter = usd -> argPesoToUsdRate.multiply(new BigDecimal(usd));

Function<BigDecimal, String> argentineCurrencyFormatter = price -> {
  Currency currentCurrency = Currency.getInstance(argLocale);
  NumberFormat currencyFormatter =
    NumberFormat.getCurrencyInstance(argLocale);
  return String.format("%s (%s)",
    currencyFormatter.format(price),
    currentCurrency.getDisplayName()
  );
};

Function<Integer, String> testConverter = usdToArgentinePesoConverter.andThen(argentineCurrencyFormatter);

return getConvertedPriceStatements(records, testConverter
  // TODO: Correct this.  It should to convert AND format.  However, there is room parameter wise for only one Function...hmmm.
  //homeValueIndex -> "FIXME!!!"
);

}

the result is : Expected: iterable containing ["First is $1.00 (USD) which is $15,48 (Argentine Peso)", "Second is $2.00 (USD) which is $30,96 (Argentine Peso)"] but: item 0: was "First is $1.00 (USD) which is $15,48 (้˜ฟๆ นๅปทๆฏ”็ดข)"

1 Answer

Gergely Horvath
PLUS
Gergely Horvath
Courses Plus Student 8,207 Points

Looks like "argentin peso" got translated to your language. You may try switching

currentCurrency.getDisplayName()

to this

currentCurrency.getDisplayName(Locale.forLanguageTag("en-US"))

Read more here.

Oh, thank you so much! I was stuck there, but I am wondering why it translated to my language...??

Gergely Horvath
Gergely Horvath
Courses Plus Student 8,207 Points

I guess the code wasn't ready for the possibility that currency name displays on languages other than english. As the stackoverflow post says localization isn't necessarily there. So chances are this doesn't happen to most users facing this challange. Keep on going! :)

Thanks for explaining!