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 trialTuan Zen
6,882 PointsgetDisplayName with proper case
How do I change SONY to Sony here? the method .toLowerCase() doesnt seem to work
package com.example.model;
public enum Brand {
JVC,
SONY,
COBY,
APPLE;
private String displayName;
private Brand() {}
Brand(String displayName) {
displayName = displayName.toLowerCase();
}
public String getDisplayName() {
return displayName;
}
}
2 Answers
Kourosh Raeen
23,733 PointsHi Tuan - The constructor expects a display name passed in so change
public enum Brand {
JVC,
SONY,
COBY,
APPLE;
to
public enum Brand {
JVC("JVC"),
SONY("Sony"),
COBY("Coby"),
APPLE("Apple");
Also, in the constructor the parameter name and the private member variable have the same name, so either change the member variable name to mDisplayName
or use the this
keyword:
package com.example.model;
public enum Brand {
// Your code here
JVC("JVC"),
SONY("Sony"),
COBY("Coby"),
APPLE("Apple");
private String displayName;
private Brand() {}
Brand(String displayName) {
this.displayName = displayName;
}
public String getDisplayName() {
return displayName;
}
}
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsI think this line is wrong: displayName = displayName.toLowerCase(); In constructor if names of argument "Brand (String displayName)" and member "private String displayName" variable are the same, you have to use this keyword: this.displayName = displayName.toLowerCase();