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 trialMichael Harper
14,741 PointsValidation test failing
No compiler errors are thrown in Preview, but solution fails with error: Bummer! Expected "m_first_name" to fail but it passed.
Where is "m_first_name" coming from in this example?
public class TeacherAssistant {
public static String validatedFieldName(String fieldName) {
// These things should be verified:
// 1. Member fields must start with an 'm'
if ( fieldName.charAt(0) != 'm') {
throw new IllegalArgumentException("member field " +fieldName+ " doesn't start with m.");
}
// 2. The second letter in the field name must be uppercased to ensure camel-casing
boolean lowCase = Character.isLowerCase(fieldName.charAt(1));
if (lowCase) {
throw new IllegalArgumentException("member field " +fieldName+ " second char is not upper case.");
}
return fieldName;
}
}
1 Answer
Grigorij Schleifer
10,365 PointsHi MIchael,
you can use this:
boolean lowCase = Character.isUpperCase(fieldName.charAt(1);
or:
if (!Character.isUpperCase(fieldName.charAt(1))) {
throw new IllegalArgumentException("some massage");
}
for the upper case examination.
Grigorij
Michael Harper
14,741 PointsMichael Harper
14,741 PointsThanks G, using isUpperCase() instead of isLowerCase() seems to deal with illegal characters in a more expected way.
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHey M
the logic of your code is good, but I think the challenge wants us to use isUpperCase() method.
See you in the forum
G