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

Help!!! Applying Discount Code Challenge

I'm new to programming. I'm taking the Java course and I'm stuck with this challenge task 1 of 2.

Issue: Compile error

Target: 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.

''' import java.io.*;

String Str = new String();

private String normalizeDiscountCode (String discountCode){ this.discountCode = str.toUpperCase(discountCode); return discountCode; } public void applyDiscountCode(String discountCode){ this.discountCode = normalizeDiscountCode(discountCode); }'''

I've followed the instructions on how to use toUpperCase() method on the link (https://www.tutorialspoint.com/java/java_string_touppercase.htm)

1 Answer

Hi there. You don't really need to create a new string variable Str here. You can call the toUpperCase method directly on the string that was passed in and return it that way, without any intermediary. All we need to do is accept the discount code as input to the method and return a version in all caps. Try something like:

private String normalizeDiscountCode(String discountCode) {

return discountCode.toUpperCase();

}

Thank you much. This helped.