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 trialOshedhe Munasinghe
8,108 Points91%, almost correct but getting wrong by argentinaRecordsAreFormattedAndConverted
I saw old post where students are saying that it's a bug?
Well I have got the same issue and can't solve. It says
java.lang.AssertionError:
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 (argentinsk peso)"
Here is my result and to be honest I don't understand what he meant the first TODO.
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()
);
};
return getConvertedPriceStatements(records,
usdToArgentinePesoConverter.andThen(argentineCurrencyFormatter));
}
2 Answers
Oshedhe Munasinghe
8,108 PointsIt took me more than 1 hours to understand your mention about this line π.
return String.format("%s (%s)",
Because I personally don't see that there is a space between the two placeholders. I never touch them either.
Anyway The answer is place another replace method on currencyFormatter. Like this..
currencyFormatter.format(price).replace("\u00a0", ""),
Here all students, you can copy-paste my answer without painful. Please give me a vote up because I deserve it π
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).replace("\u00a0", ""),
currentCurrency.getDisplayName(Locale.forLanguageTag("en-US")).replace("\u00a0", "")
);
};
Jason Anders
Treehouse Moderator 145,860 PointsHi Oshedhe,
Your code is actually correct and does pass all tests when I copy/paste it from your post to my editor, and also passes when I upload to the challenge.
I believe the problem may be coming from your location and the translation of locales. If you look at the code above, the returned value is "argentinsk"
instead of the en-US "Argentine"
.
The first thing you should try is to just upload the submission as is. I think the code checker will put in the correct locale when running the tests on the Treehouse server. If that doesn't work, you could try a suggestion put forth in this previous post from someone with a similar issue.
I hope this solves the issue, because you code is correct.
Nice work!! :)
Oshedhe Munasinghe
8,108 PointsHi I have checked this previous post so it looks like this:
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(Locale.forLanguageTag("en-US")).replace("\u00a0","")
);
};
Function<Integer, String> convertAndFormatPrice
= usdToArgentinePesoConverter.andThen(argentineCurrencyFormatter);
Argentisk is Swedish so I have changed that to English instead.. but it returned error. So I have put method replace - still it didn't work. I can't generate Submission. If you say that my code has passed it would be awesome if you can send my submission file.. because I have got bored with this challenge. I am also stucked at the last challange as well. π π‘
Here is the error:
Jason Anders
Treehouse Moderator 145,860 PointsIt looks like that other post has an extra space for the output. If you look at this line:
return String.format("%s (%s)",
There is a space between the two placeholders, so if you have a look at the error, you'll see the returned string is $ 15.48
instead of $15.48
.
With the submission, did you try to submit your original code? It should compile and form the submission? Give that a try before you try the other post's fix.
Seamus SionΓ³id
27,798 PointsSeamus SionΓ³id
27,798 PointsMany thanks Oshedhe!
Oshedhe Munasinghe
8,108 PointsOshedhe Munasinghe
8,108 Pointsno problem Seamus!!