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

delivering the MVP

hie there, can somebody help me understand what this challenge wants me to do. honestly I've just tried to work it out but um not quite sure of what i am doing

Here is my code

TeacherAssistant.java
public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {
    if (! FieldName.isFieldName ('m') ){
      throw new IllegalArgumentException ( "A letter is required");
    }
    // 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;
  }

}

4 Answers

hi Brett Dube & Rob Bridges, You also need to add:

|| !Character.isLetter(fieldName.charAt(1))

to:

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

hope it helps!!! ISAIAH S :zap:

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey there Brett,

What they're wanting you to do is check in an if statement if the first character in field name is 'm' and that the second is capitalized, if not it wants you to throw the exception, it looks like you got the exception part right, only the if statement needs to be hammered out a bit.

It will look something similar to below

 public static String validatedFieldName(String fieldName) {
    if (fieldName.charAt(0) != 'm' || !Character.isUpperCase(fieldName.charAt(1))) {
      throw new IllegalArgumentException("Sorry, that is an invalid field name");
    }
   return fieldName;
  }
Ben Wong
Ben Wong
19,426 Points

Hey Rob,

I tried your code and it doesn't seem to go through.

Kindly advise.

Thanks.

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey Ben, This code compiles and runs, are you sure you didn't copy and paste over the

public class TeacherAssistant {

and the last }

That should still be in there? I didn't include them in the code because it was just to show what the method should look like.

However, for a full code that can be copy and pasted in.

public class TeacherAssistant {

 public static String validatedFieldName(String fieldName) {
    if (fieldName.charAt(0) != 'm' || !Character.isUpperCase(fieldName.charAt(1))) {
      throw new IllegalArgumentException("Sorry, that is an invalid field name");
    }
   return fieldName;
  }

}

will work

Ben Wong
Ben Wong
19,426 Points

Got it somehow. Thanks Rob.

My code works.