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

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

I am trying to solve the validation challenge ...

I have no more ideas why this doesnt work ;(

public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {

    char mChar = 'm';  
    if(fieldName.charAt(0) != mChar){
     throw new IllegalArgumentException("he second letter in the field name must be uppercased");
    }
    char[] fieldNameChar = fieldName.toCharArray();
    if(Character.isLowerCase(fieldNameChar(charAt(1))){
     throw new IllegalArgumentException("he second letter in the field name must be uppercased");
    }
    return fieldName;
  }

}

1 Answer

Dan Johnson
Dan Johnson
40,532 Points

Here's an outline of the changes you could make:

    // The 'm' prefix is typically only used for instance variables, though this
    // won't cause any compilation issues.
    char mChar = 'm';  
    if(fieldName.charAt(0) != mChar) {
     throw new IllegalArgumentException("The first letter should be an \'m\'.");
    }

    char[] fieldNameChar = fieldName.toCharArray();
    // Access elements of an array with [] instead of ().
    // charAt is a method of the String class, so you can't call it on its own.
    if(Character.isLowerCase(fieldNameChar[1])) {
     throw new IllegalArgumentException("The second letter in the field name must be uppercased");
    }

    // For the final check, make sure the second letter is a character.
    // There's a static method of the Character class that can do this.

    // if the second character isn't a letter
    //     throw an exception