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

Looks like you threw a different exception instead of the IllegalArgumentException. java.lang.NullPointerException.

What is wrong here ?

TeacherAssistant.java
import java.io.Console;
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 mFieldName;
    Console console = System.console();
    mFieldName = console.readLine();
    if(fieldName != mFieldName){
      throw new IllegalArgumentException("Valuse that you passed doesn't validate the field name");
    }
    return fieldName;
  }

}

1 Answer

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Ivan

It looks like you're not checking the input correctly, you need to follow the directions given in order to validate the passed in String. The way I did it is posted below however i'm not sure if you have covered these methods or not.

In case you want to figure this out for yourself my hint to you would be "split the String into an array first in order to separate the individual characters, then check the indexes of the characters to validate".

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[] fieldArray =  fieldName.toCharArray();

    if(fieldArray[0] == 'm' && Character.isUpperCase(fieldArray[1])){

      return fieldName;

    }else{

      throw new IllegalArgumentException();

    }


  }

}

Hope this helps

Daniel

This might be more appropriate at this stage of the course.

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 charOne = fieldName.charAt(0);
    char charTwo = fieldName.charAt(1);
    if(charOne == 'm' && Character.isUpperCase(charTwo)) {
      return fieldName;
    } else {
      throw new IllegalArgumentException();
    }


  }

}