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 trial

Java Java Objects (Retired) Delivering the MVP Validation

isral bustami
PLUS
isral bustami
Courses Plus Student 5,932 Points

little hint for this challenge please..

i can't get the way to solve this challenge.. or maybe i am to slow to follow this lesson.. i have no experience at all with this but i am trying very hard to learn and absorb this course.. i realy need hint on this challenge.. thanks

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

    String mFirstName = "";

    if (fieldName.charAt(0) != 'm') {
        throw new IllegalArgumentException("Member field must start with an 'm' "); 
      }
     mFirstName = fieldName;    
    return fieldName;
  }

}

3 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Well, I didn't take any Java courses at Treehouse, so I don't know how the instructor want you to approach this problem, but if I were to write it, it'd be sth like this

public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {
    if (fieldName.charAt(0) != 'm' || !Character.isUpperCase(fieldName.charAt(1)) ) {
        throw new IllegalArgumentException(" Illegal field name "); 
      }
    return fieldName;
  }

}

Any questions here?

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Well, you haven't written code for this part of the requirement yet.

The second letter in the field name must be uppercased to ensure camel-casing

isral bustami
isral bustami
Courses Plus Student 5,932 Points

that one i don't know what to write.. is it using charAt(1)... if it is, what is the next code afterward..

isral bustami
PLUS
isral bustami
Courses Plus Student 5,932 Points

that is how to write the code... i try this before

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
     String mFirstName = "";

    if (fieldName.charAt(0) != 'm') {
        throw new IllegalArgumentException("Member field must start with an 'm' "); 
      }
     mFirstName = fieldName;  
     fieldName = fieldName.charAt(1);
    if (! fieldName.isUpperCase()) {
       throw new IllegalArgumentException("The second letter in the field name must be uppercased");
    }
    return fieldName;
  }

}

thank you much for your help..