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 trialISAIAH S
1,409 PointsI 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
Jess Sanders
12,086 PointsThanks for sharing!
Here is my TreeStory.
"Fred is a smiling frog. They are always slowly sneezing above the cloud."
ISAIAH S
1,409 PointsISAIAH S
1,409 PointsThanks! I recently changed it to: