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

Stuck at this point on the Java project

trying to understand what im doing wrong here....

For this first task, create a new private method named normalizeDiscountCode. It should take the discount code that is passed into the method and return the uppercase version. Call it from the current applyDiscountCode method and set this.discountCode to the result.

this is what i came up with...

private String normalizeDiscountCode(String discountCode){
    Order order = new Order("bascketball",100);
    order.applyDiscountCode("hooper");
    order.getDiscountCode();
    discountCode.toUpperCase();
    return this.discountCode;    
  }

What im i going wrong here?

Order.java
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 void applyDiscountCode(String discountCode) {
    this.discountCode = discountCode; // call normalizeDiscountCode here
  }
  private String normalizeDiscountCode(String discountCode){
    Order order = new Order("bascketball",100);
    order.applyDiscountCode("hooper");
    order.getDiscountCode();
    discountCode.toUpperCase(); // return this!
    return this.discountCode;    
  }
}

3 Answers

Hi Troy,

The challenge mentions nothing about an Order. There are two tasks. One, is to call the normalizeDiscountCode method from within applyDiscountCode; you've done that. Second, the new normalizeDiscountCode method should return the uppercase version of the string it receives.

The applyDiscountCode method has the responsibility of managing the member variable this.discountCode. Don't amend that in normalizeDiscountCode - that method just receives a string and returns it, in uppercase form. That's it's single responsibility (at this stage!).

So, you've got applyDiscountCode done - excellent. Now, inside normaliseDiscountCode you want one line of code which just returns the uppercase version of the string it received.

Steve.

Hi Troy,

You have two tasks here.

First, in applyDiscountCode you want to set this.discountCode to the returned value coming back from normalizeDiscountCode.

Create the normalizeDiscountCode method - you've done that fine. Inside it, you have the second task. Just return the upper case version of the argument passed in. You've called that discountCode so, just convert that to upper case and return it from the method.

Make sense?

Let me know how you get on.

Steve.

I added a couple of comments in your code to assist.

Hi Steve, i have still been working on this and it not working. this is would i'm doing now.

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

  private String normalizeDiscountCode(String discountCode){
    Order order = new Order("bascketball",100);
    order.applyDiscountCode("hooper");
    order.getDiscountCode();
    return this.discountCode.toUpperCase();  
  }