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

Angel Brambila
Angel Brambila
5,847 Points

I Think Im Lost X_X

i make this code, i try it on the repl, the validation of each one, but in the code challenge, it said "Expected m_first to fail" but it pass.

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  

    char firstLetter = 'm',
         secondLetter = fieldName.charAt(1);
    boolean secondVal = (Character.isLetter(secondLetter) && Character.isUpperCase(secondLetter));
    if (firstLetter != fieldName.charAt(0) && secondVal == false) {
    throw new IllegalArgumentException (firstLetter + "is not m character and " + secondLetter + "Is not a letter"); 
    }
    return fieldName;
  }

}

2 Answers

Christopher Augg
Christopher Augg
21,223 Points

Hello Angel,

You actually did a great job on this. You only have 1 logical error in your code. The error you are getting is saying that the code should have thrown an exception because "m_first" should not pass validation since _ does not meet the requirements. This gives a hint as to where your error is in your code.

Hint: If a member field must start with the letter 'm' AND (&&) a member field's second character must be an uppercase letter, then validation fails if one OR (||) the other fails and we should throw an exception.

Your logical error is in this part of your code:

        if (firstLetter != fieldName.charAt(0) && secondVal == false) {
           throw new IllegalArgumentException (firstLetter + "is not m character and " + secondLetter + "Is not a letter"); 
        }

Regards,

Chris

Angel Brambila
Angel Brambila
5,847 Points

True, i solve it yesterday, i see my mistake, i facepalm really hard xD, thank you Chris :D!. I'll keep practicing :).

P.S : Sorry if my english is not really good, im from Mexico :3.