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

I fixed some issues in TreeStory. Wanna check it out?

Here it is:

import java.io.Console;

public class TreeStory {

    public static void main(String[] args) {
        Console console = System.console();
        /*  Some terms:
            noun - Person, place or thing
            verb - An action
            adjective - A description used to modify or describe a noun
            Enter your amazing code here!
        */
      //__Name__ is a __Adjective__ __Noun__. They are always __Adverb__ __Verb__ __Preposition__ the __Object of the Preposition__.
      String ageAsString = console.readLine("How old are you?  ");
      int age = Integer.parseInt(ageAsString);
        if (age < 13) {
          throw new IllegalArgumentException("Sorry, you must be at least 13 to use this program.\n");
        }
      String name = console.readLine("Enter a name:  ");
String adjective = console.readLine("Enter an adjective:  ");
        String noun = console.readLine("Enter a noun:  ");
        boolean isInvalidWord = (noun.equalsIgnoreCase("dork") || 
                         noun.equalsIgnoreCase("jerk"));
          if (isInvalidWord) {
        throw new IllegalArgumentException("That language is not allowed.\n\n");
          }
String adverb = console.readLine("Enter an adverb:  ");
String verb = console.readLine("Enter a verb ending with -ing:  ");
String preposition = console.readLine("Enter a preposition:  ");
String objectPreposition = console.readLine("Enter a noun:  ");
String isAdjective = adjective;
adjective = isAdjective.toLowerCase();
String isNoun = noun;
noun = isNoun.toLowerCase();
String isAdverb = adverb;
adverb = isAdverb.toLowerCase();
String isVerb = verb;
verb = isVerb.toLowerCase();
String isPreposition = preposition;
preposition = isPreposition.toLowerCase();
String isObjectPreposition = objectPreposition;
objectPreposition = isObjectPreposition.toLowerCase();
char firstChar = adjective.charAt(0);
if (firstChar == 'a' || (firstChar == 'e' || (firstChar == 'i' || (firstChar == 'o' || (firstChar == 'u'))))){
  System.out.printf("Your TreeStory:\n\n-----------------------------------------------------------------\n");
      console.printf("%s is an %s %s. ", name, adjective, noun);
      } else {
      System.out.println("\nYour TreeStory:\n-----------------------------------------------------------------");
      console.printf("%s is a %s %s. ", name, adjective, noun);}
          console.printf("They are always %s %s %s the %s.\n", adverb, verb, preposition, objectPreposition);
      }

      }

This code will:

  • Ask how old you are

  • Throw an exception if you are under 13

  • Ask for a name, adjective, noun, adverb, a verb ending with -ing, a preposition, and another noun

  • Test if adjective begins with a vowel. If so, it will replace 'a' with 'an' in the following sentence:

  • Write out: ' Your TreeStrory:

-------------------------------------------------------------------------------------------------------------------------------------------------------

name is a\an adjective noun . They are always adverb verb preposition the objectOfPreposition . '

1 Answer

Thanks for sharing!

Here is my TreeStory.

"Fred is a smiling frog. They are always slowly sneezing above the cloud."

Thanks! I recently changed it to:

  import java.io.Console; 
  public class TreeStory {
  static Console console = System.console();
  public static void main(String[] args) {
  /*  Some terms:
    Adverb - A description used to modify a verb, adjective, or another adverb!
    Adjective - A description used to modify or describe a noun.
    Noun - Person, place or thing.
    Preposition - A word which works with a noun.
    Example: "over the fence," or "in the sky".
    Verb - An action.
      Enter your amazing code here!
    __Name__ is a\an __Adjective__ __Noun__. They are always __Adverb__ __Verb__ __Preposition__ the __Object of the Preposition__.*/
  String ageAsString = console.readLine(" How old are you?  ");
  int age = Integer.parseInt(ageAsString);
  if (age < 13) {
    throw new IllegalArgumentException("Sorry, you must be at least 13 to use this program.\n");
}

  System.out.println("\n    Some terms:\n Adverb - A description used to modify a verb, adjective, or another adverb!\n Adjective - A description used to modify or describe a noun.\n Noun - Person, place or thing.\n Preposition - A word which works with a noun. \n    Example: \"over the fence,\" or \"in the sky\".\n Verb - An action.\n");
  String name = console.readLine(" Enter a name:  ");

    String maleOrFemale = "";
    String gender = "";
do {    
  maleOrFemale = console.readLine("\n Is %s male or female?  ", name);
if (maleOrFemale.equalsIgnoreCase("male")) {
  gender = "He";

}
if (maleOrFemale.equalsIgnoreCase("female")) {
  gender = "She";
}

  if (!maleOrFemale.equalsIgnoreCase("male") || (!maleOrFemale.equalsIgnoreCase("female"))) {
    System.out.println("\nPlease enter \"male,\" or \"female\". Try again.");
  }
} while(!maleOrFemale.equalsIgnoreCase("male") || (!maleOrFemale.equalsIgnoreCase("female")));

String adjective = console.readLine("\n Enter an adjective:  ");
String noun = console.readLine("\n Enter a noun:  ");
boolean isInvalidWord = (noun.equalsIgnoreCase("dork") || 
                         noun.equalsIgnoreCase("jerk"));
if(isInvalidWord) {
  throw new IllegalArgumentException("No name calling.\n\n");
}

  String adverb = console.readLine("\n Enter an adverb ending with -ly:  ");
  String verb = console.readLine("\n Enter a verb ending with -ing:  ");
    String preposition = console.readLine("\n Enter a preposition:  ");
    String objectPreposition = console.readLine("\n Enter a noun:  ");
      String isAdjective = adjective;
      adjective = isAdjective.toLowerCase();

        String isNoun = noun;
        noun = isNoun.toLowerCase();

          String isAdverb = adverb;
          adverb = isAdverb.toLowerCase();

            String isVerb = verb;
            verb = isVerb.toLowerCase();

              String isPreposition = preposition;
              preposition = isPreposition.toLowerCase();

                String isObjectPreposition = objectPreposition;
                objectPreposition = isObjectPreposition.toLowerCase();

    String partsOfSpeech = adjective + noun + adverb + verb + preposition + objectPreposition;
  char firstChar = adjective.charAt(0);
if (firstChar == 'a' || (firstChar == 'e' || (firstChar == 'i' || (firstChar == 'o' || (firstChar == 'u'))))) {
  System.out.printf("\n Your Story:\n\n-----------------------------------------------------------------\n\n");
  console.printf("  %s is an %s %s. ", name, adjective, noun);
} else {
  System.out.println("\n Your Story:\n-----------------------------------------------------------------\n\n");
  console.printf(" %s is a %s %s. ", name, adjective, noun);
}

  console.printf(" %s is always %s %s %s the %s.\n", gender, adverb, verb, preposition, objectPreposition);
}
}