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

Richard Groot
Richard Groot
4,432 Points

I'm actually confused on what I'm actually supposed to be doing in this code test. I'm probably missing something huge.

I know I'm supposed to throw a new exception. I'm guessing it's different inputs I'm supposed to do. What I'm trying to do is show that if "fieldName" is a string it throws and exception. However, I'm not sure how to do what I'm trying to do. Or maybe I'm completely missing the point of the lesson.

TeacherAssistant.java
public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {
    String mString = null;
    if(fieldName != mString){
    throw new IllegalArgumentException("Something is supposed to happen");
    }
    // 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;
  }

}

2 Answers

The things to do in this particular code challenge are in the comments of the code. Here are those comments separated from everything else.

// 1.  Member fields must start with an 'm'
// 2.  The second letter in the field name must be uppercased to ensure camel-casing

You are totally on the right track with your if statement that will throw an error. Just replace the logic there currently (checking for null) with something like...

if (fieldName.charAt(0) != 'm') {
  // throw error
}

The above should cover case 1 but you'll also want to check for case 2. Most likely with an "or" statement.

Hope this helps without giving too much away. ^_^

Richard Groot
Richard Groot
4,432 Points

Thanks to you. I've now completed the challenge! :D

Richard Groot
Richard Groot
4,432 Points

ohh ok I understand I thought those were just saying like if I personally made a member variable it had to start with an "m". Thank you so much.