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 Basics Perfecting the Prototype Censoring Words - Looping Until the Value Passes

[SOLVED] Adding the correct pronoun to my TreeStory

So I want to add some code so that the final story will say "He is always adverb verbing." or "She is always adverb verbing," depending on the person's gender. I realize the easiest way would be to create another string called gender with some awkward question like "Are you a he or a she?" in the console.readLine, but I'd like to sound a little smoother. The other option is for the computer to somehow guess the gender based on the name, and I don't want to do that either--too complicated for me!

So, I first I made:

String gender = console.readline("Is this person male or female?");

And then later I wantedd to create an if/else statement that redefines the gender string with the correct pronoun, like:

if (gender.equalsIgnoreCase("male")) { String gender = ("He"); } else String gender = ("She");

But...not surprisingly, that didn't work. So maybe I have to create another variable? Or a boolean that registers true if the gender is "female" and then turns into a string that says "She"? Or is there an easier way? Please help!

SOLVED. In case anyone is interested, I added the if/then statement to the very end like this:

if (gender.equalsIgnoreCase("male")) { console.printf("Your TreeStory:\n-----------------------------------------\n"); console.printf("%s is a %s %s. He is always %s %s.", name, adjective, noun, adverb, verb); } else { console.printf("Your TreeStory:\n-----------------------------------------\n"); console.printf("%s is a %s %s. She is always %s %s.", name, adjective, noun, adverb, verb);

Lee Reynolds Jr.
Lee Reynolds Jr.
5,160 Points

I was just browsing through the forum and saw this post. I like it and I love how you figured it out. You did it in a much simpler way than I would have figured it out haha. Keep up the good work and Happy Coding :)

Ken Alger
Ken Alger
Treehouse Teacher

edited title for [SOLVED]

1 Answer

You could have also done:

   static Console console = System.console();
      String maleOrFemale = console.readLine("Is this person male or female?  ");
if (maleOrFemale.equalsIgnoreCase("male")) { String gender = "He"; } else { String gender = "She";}