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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Philippe Doreau](https://secure.gravatar.com/avatar/282f0a7ae6a2bfcf939d30ef8759298e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Philippe Doreau
18,799 PointsCan't pass the last Test (argentinaRecordsAreFormattedAndConverted)
On this exersice, Im totally blocked and can pass the last test, I put the the two functions "usdToArgentinePesoConverter" and "argentineCurrencyFormatter" together in the same function by using "andThen", but after in the return statement I don't know what to do, if I use the new Function gathering "usdToArgentinePesoConverter" and "argentineCurrencyFormatter" I can see the new price in Peso Argentin, but the exercise is not validated by the test, and what is homeValueIndex, and How to use it with the new Function ?
If someone has already did this exercise, I would appreciate some help, Thank you very much
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,
// TODO: Correct this. It should to convert AND format. However, there is room parameter wise for only one Function...hmmm.
//homeValueIndex ->
testConverter
);
}
5 Answers
![Fahad Mutair](https://uploads.teamtreehouse.com/production/profile-photos/6260962/micro_download.jpg)
Fahad Mutair
10,359 Pointshi Philippe Doreau ,i know its not that easy and it took time from me to solve this challenge
here's my code
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> indeedToArgentineCurrencyConverter = usdToArgentinePesoConverter.andThen(argentineCurrencyFormatter);
return getConvertedPriceStatements(records,
// TODO: Correct this. It should to convert AND format. However, there is room parameter wise for only one Function...hmmm.
indeedToArgentineCurrencyConverter.andThen(
(String homeValueIndex) -> String.format(homeValueIndex, homeValueIndex))
);
}
![Philippe Doreau](https://secure.gravatar.com/avatar/282f0a7ae6a2bfcf939d30ef8759298e?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Philippe Doreau
18,799 PointsThank you Fahad for your help, I will try to know to understand the logic : )
![Micros Solomon Marumbi](https://secure.gravatar.com/avatar/dbad2b2e68b29d57e28eece4990450be?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Micros Solomon Marumbi
12,014 PointsYou saved me, thanks!
![Philippe Doreau](https://secure.gravatar.com/avatar/282f0a7ae6a2bfcf939d30ef8759298e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Philippe Doreau
18,799 PointsThe code can a be a little bit simpler like below, and it works with the lambda
Function<Integer, String> argentinConverter = usdToArgentinePesoConverter.andThen(argentineCurrencyFormatter);
return getConvertedPriceStatements(records,
// TODO: Correct this. It should to convert AND format. However, there is room parameter wise for only one Function...hmmm.
argentinConverter.andThen(
homeValueIndex -> homeValueIndex
)
);
}
Moderator Edit: Added Markdown to the code so that it is in a readable format for the Community.
![Fahad Mutair](https://uploads.teamtreehouse.com/production/profile-photos/6260962/micro_download.jpg)
Fahad Mutair
10,359 PointsGreat work
![Arran Cardnell](https://secure.gravatar.com/avatar/d5ca123efa69e831e22bcc845047013e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Arran Cardnell
12,313 PointsI was also banging my head against this one for a while. The problem indeed turned out to be the non-breaking space as suggested above, so thank you to Nick for that.
To solve this I modified the getPriceConversionForRecord method as follows:
public static String getPriceConversionForRecord(HousingRecord record, Function<Integer, String> priceConverter) {
NumberFormat usFormatter = NumberFormat.getCurrencyInstance(Locale.US);
return String.format("%s is %s (USD) which is %s",
record.getRegionName(),
usFormatter.format(record.getCurrentHomeValueIndex()),
priceConverter.apply(record.getCurrentHomeValueIndex())
).replaceAll("\u00a0", " ");
}
This replaces all non-breaking spaces with normal spaces, allowing the test to pass.
![Ben Basty](https://uploads.teamtreehouse.com/production/profile-photos/9866322/micro_profilepic.jpg)
Ben Basty
23,772 Pointsi followed all steps exactly but i still have the same error : 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 (Argentine Peso)" Anyone pls help me ?
![William Daugherty](https://uploads.teamtreehouse.com/production/profile-photos/6269092/micro_profile__2_.jpg)
William Daugherty
Full Stack JavaScript Techdegree Graduate 30,935 PointsI'm having the same issue, seems like somehow there's a space between the '$' sign and the integers and that's why the perpareSubmission can't recognize the String as working
![Nick Frozz](https://uploads.teamtreehouse.com/production/profile-photos/9329062/micro_Logo_copy.jpg)
Nick Frozz
31,289 PointsActually, it's ($--> <--15,48) not a "space" it's something called "U+00A0 : NO-BREAK SPACE [NBSP]" character. So you can pass this challenge by replacing the code in src/test/com.teamtreehouse.challenges.homes/MainTest
from:
"First is $1.00 (USD) which is $15,48 (Argentine Peso)",
"Second is $2.00 (USD) which is $30,96 (Argentine Peso)"
to:
"First is $1.00 (USD) which is $ 15,48 (Argentine Peso)",
"Second is $2.00 (USD) which is $ 30,96 (Argentine Peso)"
Philippe Doreau
18,799 PointsPhilippe Doreau
18,799 PointsI can see this error message:
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 (peso argentin)"