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 trialJames Kane
Front End Web Development Techdegree Student 3,070 PointsNot sure where i'm going wrong here, help please
got this error message :
./Order.java:12: error: incompatible types: String cannot be converted to Locale this.discountCode = String.toUpperCase(discountCode);
Any help much appreciated :)
public class Order {
private String itemName;
private int priceInCents;
private String discountCode;
public Order(String itemName, int priceInCents) {
this.itemName = itemName;
this.priceInCents = priceInCents;
}
public String normalizeDiscountCode(String discountCode) {
this.discountCode = String.toUpperCase(discountCode);
}
public void applyDiscountCode(String discountCode) {
this.discountCode = discountCode;
}
}
[MOD: edited code block for brevity - srh]
2 Answers
Steve Hunter
57,712 PointsHi James,
You want to return the upper cased discount code from normalizeDiscountCode
to applyDiscountCode
where you call the method. In that latter method, you set this.discountCode
.
So, inside applyDiscountCode
call normalizeDiscountCode
and pass discountCode
at the parameter. That will return a string, assign that into this.discountCode
. Then, inside normalizeDiscountCode
convert the received string, discountCode
to upper case & just return
that.
Make sense?
Steve.
Alexander Matos Olivo
3,085 PointsString.toUpperCase(discountCode), this is not the way to call the function toUpperCase, doit from the variable itself,
discountCode.toUpperCase();
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsAlso, you call the
toUpperCase()
method on the string itself. It isn't a class method. So, take the variable name and chain, using dot notation, the method onto it. It doesn't take a parameter:discountCode.toUpperCase(); // return this
James Kane
Front End Web Development Techdegree Student 3,070 PointsJames Kane
Front End Web Development Techdegree Student 3,070 PointsThank you Steve.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo problem! Good luck with the next task - it gets a little trickier.