Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Delivering the MVP Validation

Aldrich Alviar
Aldrich Alviar
2,745 Points

validation

validation task

TeacherAssistant.java
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
    return fieldName;
  }

}
Benjamin Barslev Nielsen
Benjamin Barslev Nielsen
18,958 Points

What is your question? It is easier to help you, if you present your current attempt for the solution?

Aldrich Alviar
Aldrich Alviar
2,745 Points

validatedFieldName method it will return the validated field name. if value passed in doesn't meet the requirements, throw an Illegal argument exception?

1 Answer

Simon Coates
Simon Coates
28,693 Points

the following seems to pass.

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 first =  fieldName.charAt(0);
    char second = fieldName.charAt(1);
    if(first != 'm'){
      throw new IllegalArgumentException( "field name should start with m.");
    }
    if(!Character.isUpperCase(second )){
      throw new IllegalArgumentException( "second letter should be uppercase");
    }
    return fieldName;
  }
}
Aldrich Alviar
Aldrich Alviar
2,745 Points

thank you Sir I will continue to practice coding