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

Saad Ahmed
Saad Ahmed
7,090 Points

I keep getting this error: "Expected "m_first_name" to fail but it passed

Why wont this pass?

TeacherAssistant.java
public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {
    char m_first_name = fieldName.charAt(0);
    char secondLetter = fieldName.charAt(1);

    if (m_first_name != 'm') {
      throw new IllegalArgumentException("Not valid, first letter should be 'm'.");
    }
    if(secondLetter != Character.toUpperCase(secondLetter)) {
      throw new IllegalArgumentException("Second letter should be captitalized");
    }
    // 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;
    }


}

3 Answers

Hi Saad,

you also have to check if secondLetter is actually a letter but you are only checking if secondLetter is uppercased. After you fixed that you should be good to go.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

You should also change your variable back to firstLetter to help remove your confusion. Looks great!

private char validateGuess(char letter) {
    if (!Character.isLetter(letter)) {
      throw new IllegalArgumentException("A letter is required."
    }
    letter = Character.toLowerCase(letter);
    if (mMisses.indexOf(letter) >= 0 || mHits.indexOf(letter) >= 0) { 
      throw new IllegalArgumentException(letter + " has already been guessed")           }
    return letter;
  }
  • The above code is the example to follow.
  • We care about charAt for this challenge, rather than indexOf
  • In pseudocode, we want to check for the following condition, and throw an error: " if the character at index 0 of fieldName does not equal 'm' OR the character at index 1 of fieldName is not upper case"