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 trialEnyang Mercy
Courses Plus Student 2,339 PointsSTUCK!!!
Stuck here.
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 getItemName() {
return itemName;
}
public int getPriceInCents() {
return priceInCents;
}
public String getDiscountCode() {
return discountCode;
}
public void applyDiscountCode(String discountCode) {
this.discountCode = discountCode;
}
private char normalizeDiscountCode() {
}
2 Answers
Steve Hunter
57,712 PointsHi there,
There was another thread on this same point that I added an answer to yesterday - let's start again here.
First, let's create the new method, normalizeDiscountCode
. This is a private
method that returns a String
. It also accepts a String
as a parameter. So, start with the keyword private
, then put the return type, String
. Next comes the method name which is followed by brackets. Inside the brackets declare a String
and call it something sensible, like discountCode
. Putting that together looks like:
private String normalizeDiscountCode(String discountCode){
// do stuff in here
}
Inside the method, initially, we want to return the uppercase version of the code that was passed in. I did a Google for Java uppercase string which told me that the method required is called toUpperCase()
. You use that with dot notation on the incoming string called discountCode
and send it back to the caller using return
.
private String normalizeDiscountCode(String discountCode){
// do stuff in here
return discountCode.toUpperCase();
}
Now, use that method in the existing applyDiscountCode
method. In there, change this line:
this.discountCode = discountCode;
to use the normalize method on the discount code to the right of the equals. Send in discountCode
into the method:
this.discountCode = normalizeDiscountCode(discountCode);
I hope that helps.
Steve.