Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Delivering the MVP Applying a Discount Code

Not 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

Hi 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?


Also, 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

Thank you Steve.

No problem! Good luck with the next task - it gets a little trickier. :smile: :+1: :muscle:

Alexander Matos Olivo
Alexander Matos Olivo
3,085 Points

String.toUpperCase(discountCode), this is not the way to call the function toUpperCase, doit from the variable itself,