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

Ben Morse
Ben Morse
6,068 Points

Stuck on a Challenge quiz

Been at this for hours and I'm getting a char and boolean error. It keeps pointing to the 2nd not equals symbol.

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 ch;
    if (fieldName.charAt(0) != 'm' && fieldName.charAt(0) != Character.isUpperCase(ch) ) {
      throw new IllegalArgumentException( "Must enter a validated method name" );
    }    
    return fieldName;
  }



}

1 Answer

Hi Ben,

You're nearly there with this. I hadn't done this course so I just had a look at the code challenge.

First, I tested for == rather than != - both should work fine, though.

if (fieldName.charAt(0) == 'm' && Character.isUpperCase(fieldName.charAt(1))) { 

  return fieldName;

} else {

  throw new IllegalArgumentException( "Must enter a validated method name" );

}

So, you're testing to see if the first character is 'm' and that the second character (you tested the first twice) is a capital. The order that the statements need applying got a little confused in your first attempt. First, get the character you want to test as being uppercase, fieldName.charAt(1) then wrap the test around that, Character.isUpperCase(fieldName.charAt(1))

Chain those together with an && in the if conditional and if they pass, return the fieldName - else they've failed so throw the exception.

I hope that makes sense!

Steve.

Ben Morse
Ben Morse
6,068 Points

Thanks friend. I must have passed the parameters in wrong for the isUpperCase() method. Also saw that i was testing the first letter twice! Coding late with no energy is not good for me. It was bothering me late last night. I got really frustrated and didn't want to ask for up....but when you are stuck, you are stuck.

I tried googling the error and I couldn't find the answers i was looking for. Don't know how i could have come to the conclusion you did...more studying for me to do :D

Thanks again!

You'd done most of the heavy-lifting with that question, to be honest. You'd identified how the solution could be reached, by using the ifmethod, and also what other functions to use to get the right tests in place.

I just got the order sorted so you were pretty much on it.

Ben Morse
Ben Morse
6,068 Points

Seems to be one of my problems which is sorting it out...all jumbled up...thanks again :)