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

Make sure you set the this.discountCode = normalizeDiscountCode(discountCode)

Hi, I have tried declaring this.discountCode = discountCode but I'm still getting the same error.

public class Order {
  private String itemName;
  private int priceInCents;
  private String discountCode;

  private String normalizeDiscountCode (String discountCode) {
     this.discountCode = normalizeDiscountCode(discountCode);
     for (char letter : discountCode.toCharArray()) {
        if (! (Character.isLetter(letter) || letter == '$')) {
           throw new IllegalArgumentException ("Invalid discountcode has been used");
          }
       }
        return discountCode.toUpperCase();
  }

  public Order(String itemName, int priceInCents) {
    this.itemName = itemName;
    this.priceInCents = priceInCents;
  }

  public String getItemName() {
    return itemName;
  }

  public int getPriceInCents() {
    return priceInCents;
  }

  public String getDiscountCode() {
    return discountCode;
  }

  public void applyDiscountCode(String discountCode) {
    this.discountCode = discountCode;
  }
}

1 Answer

Shaun Sweeney
Shaun Sweeney
6,216 Points

try moving this line into the applyDiscountCode method . should not be in the normalizeDiscountCode method. this.discountCode = normalizeDiscountCode(discountCode);