Java Java Basics Perfecting the Prototype Censoring Words - Using Logical ORs

Kirk Yale
Kirk Yale
2,126 Points

censoring words using logical ors is breaking

I am not sure why this program is coming up with errors? can someone help me? Thank you! Here's the code:

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!
    */
    // This is practice
    /* I will ask some questions to complete a sentence.
       I also want to put censoring restrictions on it.
       Let's see how I do */

    console.printf("let\'s start the program-shall we?" \n);
    String ageAsString = console.readLine("How old are you?:  ");
    int age = Integer.parseInt(ageAsString);

    //start age restriction

    if (age < 13) {
       console.printf("you are not old enough!  The system will now exit.");
       System.exit( 0 );
    }

    String name = console.readLine("First, What is your name?:  ");
    String place = console.readLine("Give me a name of a place:  ");
    String verb = console.readLine("Now, provide me a verb:  ");
    String adjective = console.readLine("Give me an adjective:  ");
    String noun = console.readLine("Lastly, I need any noun:  "); 
    if (noun.equalsIgnoreCase("jerk") ||
        noun.equalsIgnoreCase("dork") ||
        noun.equalsIgnoreCase("dweeb")) {
        console.printf("That is not an appropriate word!  The system will now exit.");
       System.exit( 0 );
    }

    console.printf("%s went to the %s to %s %s %s", name, place, verb, adjective, noun);

}

}

Here's the console errors:

Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
TreeStory.java:18: error: illegal character: '\'
console.printf("let\'s start the program-shall we?" \n);
^
TreeStory.java:18: error: not a statement
console.printf("let\'s start the program-shall we?" \n);
^
TreeStory.java:18: error: ';' expected
console.printf("let\'s start the program-shall we?" \n);
^
TreeStory.java:36: error: illegal start of expression
noun.equalsIgnoreCase("dweeb")) {
^
4 errors

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 47,300 Points

The first error is regarding this line

console.printf("let\'s start the program-shall we?" \n);

\n needs to be enclosed in quotes. The easiest way to do this is make it part of the existing string:

console.printf("let\'s start the program-shall we?\n");
Kirk Yale
Kirk Yale
2,126 Points

This did the trick! Thank you! Happy coding!

Kirk