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