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 trialUnsubscribed User
1,691 PointsWhat am i doing wrong?
The problem ask me to check if the first letter is m and if the second letter is uppercase i should return the validated field name, but if not i should throw an exception, what exactly am i doing wrong?
Thanks in advance.
public class TeacherAssistant {
public static String validatedFieldName(String fieldName) {
// These things should be verified:
// 1. Member fields must start with an 'm'
// 2. The second letter in the field name must be uppercased to ensure camel-casing
// NOTE: To check if something is not equal use the != symbol. eg: 3 != 4
if(fieldName.charAt(0) == 'm' && fieldName.chartAt(1).isUpperCase() == true)
return fieldName;
else
throw new IllegalArgumentException("The fieldname cannot be validated because it doesn't meet the requirements!");
}
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You're doing great and hang in there! But there's a few things going on here. One is simply a typo. When your'e trying to check that the second letter is upper case, you've misspelled charAt with chartAt. Again the second problem comes with checking for that upper cased second letter. isUpperCase is a method to be called on the Character object and then we pass in a character to the method.
SPOILER ALERT
This is how I did it. Note that the curly braces in the if/else blocks are optional as you only have one line of code there. But I prefer them.
public class TeacherAssistant {
public static String validatedFieldName(String fieldName) {
// These things should be verified:
// 1. Member fields must start with an 'm'
// 2. The second letter in the field name must be uppercased to ensure camel-casing
// NOTE: To check if something is not equal use the != symbol. eg: 3 != 4
if(fieldName.charAt(0) == 'm' && Character.isUpperCase(fieldName.charAt(1))) {
return fieldName;
}
else {
throw new IllegalArgumentException("The fieldname cannot be validated because it doesn't meet the requirements!");
}
}
}
Happy coding and good luck!
Unsubscribed User
1,691 PointsUnsubscribed User
1,691 PointsThanks, it worked, i will pay more attention next time :)