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
Joe Liddon
307 PointsCensoring words with Java
Good Evening to everyone at Treehouse!
I'm currently working my way through your Java basics course and i'm having a problem with the program. Not an error as such, just that when i am asked to declare a noun by the console, it will print that the language is inappropriate regardless of whether its been filtered or not, It successfully loops back to the same question asking for a noun when a censored word is used, however even when a non-censored word is used, it will display the message that the language is inappropriate, although it moves onto the next question.
As you can imagine i am a novice, i did try fiddle with the code for awhile couldn't get it to work just made it worse with errors! Is it something to do with the scope? any help is much appreciated as i wouldn't like to move forward with the course until it's fixed!
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 alway's <adverb> <verb> //
String ageAsString = console.readLine("How old are you?: ");
int age = Integer.parseInt(ageAsString);
if (age < 13) {
console.printf("Sorry, you must be 13 or older to use this application.\n");
System.exit(0);
}
String name = console.readLine("What is your name?: ");
String adjective = console.readLine("Enter an adjective: ");
String noun;
boolean isInvalidWord;
do {
noun = console.readLine("Enter a noun: ");
isInvalidWord = (noun.equalsIgnoreCase("jerk") ||
noun.equalsIgnoreCase("dork"));
if (isInvalidWord);{
console.printf("That language is not allowed.\n\n----------Try Again.------ \n\n ");
}
}
while (isInvalidWord);
String adverb = console.readLine("Enter an adverb: ");
String verb = console.readLine("Enter a Verb: ");
{
console.printf("-----%s's TreeStory!-----\n\n", name);
console.printf("%s is a %s %s. \n", name, adjective, noun);
console.printf("They love too %s %s\n", adverb, verb);
}
}