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 trialsoo ao long tian
1,111 Pointshow to solve this?
how to solve this quiz?
public class TeacherAssistant {
public static String mFieldName;
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 != mFieldName){
throw new IllegalArgumentException( "is not allowed" );
}
return fieldName;
}
}
3 Answers
Simon Coates
28,694 Pointsmy guess is:
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
char firstChar = fieldName.charAt(0);
char secondChar = fieldName.charAt(1);
if(firstChar =='m' && Character.isUpperCase(secondChar)) {
// NOTE: To check if something is not equal use the != symbol. eg: 3 != 4
return fieldName;
} else {
throw new IllegalArgumentException("Does not meet criteria");
}
}
}
soo ao long tian
1,111 Pointsi try to use the != because the note wrote // NOTE: To check if something is not equal use the != symbol. eg: 3 != 4
but it doesn't work, is there anything wrong with my code?
it show me Bummer! Expected "m_first_name" to fail but it passed.
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
char firstChar = fieldName.charAt(0);
char secondChar = fieldName.charAt(1);
if(firstChar != 'm' && Character.isLowerCase(secondChar) ){
throw new IllegalArgumentException("doesn't meet requirement");
}else{
return fieldName;
}
}
}
Simon Coates
28,694 Pointsmaybe:
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
char firstChar = fieldName.charAt(0);
char secondChar = fieldName.charAt(1);
if(firstChar !='m' || !Character.isUpperCase(secondChar)) {
// NOTE: To check if something is not equal use the != symbol. eg: 3 != 4
throw new IllegalArgumentException("Does not meet criteria");
} else {
return fieldName;
}
}
}
soo ao long tian
1,111 Pointswow, that reply was fast, i know where is my mistake now, thanks
soo ao long tian
1,111 Pointssoo ao long tian
1,111 Pointsi understand now thanks!