Java variables: madlibs project will not print!

public class MadLibs {
  /*
  This program generates a mad libbed story.
  Author: Violet
  Date: 4/01/2020
  */
  	public static void main(String[] args){
      
      String name1 = "Jon";
      String adjective1 = "Jumpy";
      String adjective2 = "Unequaled";
      String adjective3 = "Pure";
      String verb1 = "Running";
      String noun1 = "Wedding";
      String noun2 = "Recipe";
      String noun3 = "Gene";
      String noun4 = "Passion";
      String noun5 = "Collection";
      String noun6 = "Train";
      String name2 = "Jane";
      int number = 17;
      String place1 = "Saturn";

      
      
      
      
      
      
      
     
      
      
      
      
      
      
      // story is below on line 49
      
      
      
      
      
      
      
      
      
      //The template for the story
      String story = "This morning "+name1+" woke up feeling "+adjective1+". 'It is going to be a "+adjective2+" day!' Outside, a bunch of "+noun1+"s were protesting to keep "+noun2+" in stores. They began to "+verb1+" to the rhythm of the "+noun3+", which made all the "+noun4+"s very "+adjective3+". Concerned, "+name1+" texted "+name2+", who flew "+name1+" to "+place1+" and dropped "+name1+" in a puddle of frozen "+noun5+". "+name1+" woke up in the year "+number+", in a world where "+noun6+"s ruled the world.";
system.out.println(story);
    }       
}

when i try to run the code i get the following error:

MadLibs.java:50: error: package system does not exist
system.out.println(story);
      ^
1 error

what am i doing wrong?

okay so like, take 2 on the code, based on things i’ve seen in other codecademy posts for this topic (the code still won’t compile correctly):

public class MadLibs {
  /*
  This program generates a mad libbed story.
  Author: Violet
  Date: 4/01/2020
  */
  	public static void main(String[] args){

      
      
      
      
      
      
      
     
      
      
      
String name1 = "Jon";
String adjective1 = "Jumpy";
String adjective2 = "Unequaled";
String adjective3 = "Pure";
String verb1 = "Running";
String noun1 = "Wedding";
String noun2 = "Recipe";
String noun3 = "Gene";
String noun4 = "Passion";
String noun5 = "Collection";
String noun6 = "Train";
String name2 = "Jane";
int number = 17;
String place1 = "Saturn";
      
      
      // story is below on line 46
      
      
      
      
      
      
      
      
      
      //The template for the story
      String story = "This morning "+name1+" woke up feeling "+adjective1+". 'It is going to be a "+adjective2+" day!' Outside, a bunch of "+noun1+"s were protesting to keep "+noun2+" in stores. They began to "+verb1+" to the rhythm of the "+noun3+", which made all the "+noun4+"s very "+adjective3+". Concerned, "+name1+" texted "+name2+", who flew "+name1+" to "+place1+" and dropped "+name1+" in a puddle of frozen "+noun5+". "+name1+" woke up in the year "+number+", in a world where "+noun6+"s ruled the world.";
    }     
}

and now i get the following error message:

MadLibs.java:50: error: class, interface, or enum expected
System.out.println(story);
^
1 error

okay actually i figured it out!!! i think it might have been something about where i put the print command

Welcome back to the forum!

Your original error was that you wrote system.out.println where you should have used System.out.println. (Java is, for better or worse, case sensitive.)

In your second post, the code you’ve posted can’t have produced the error given underneath - because it contains no call to System.out.println():slight_smile:

case sensitivity? i hate that (i have realized after working through a few more java lessons that Case Matters in java. i hate it <3)

thank you!!!

It makes perfect sense when you consider, for example, that in ASCII encoding the codepoint for the character A is not the same as the codepoint for the character a. (Those being 65 and 97 respectively.)

They are, to the computer, two completely different things. :slight_smile:

this is true! but i got my start in like, computer things with front-end programming (CSS and HTML), which are not case-sensitive… so moving into back-end programming is a shock!

public class MadLibs {
/*
This program generates a mad libbed story.
Author: Laura
Date: 2/19/2049
*/

public static void main(String[] args){
  String name1 = "Karlil";
  String adjective1 = "Dope";
  String adjective2 = "Frivolous";
  String noun1 = "Boxer dog";
  String noun2 = "Jesuits";
  String verb1 = "Dig";
  String noun3 = "Satan";
  String noun4 = "Aquarium";
  String adjective3 = "Chill";
  String name2 = "Yakub";
  String place1 = "North Side";
  String noun5 = "Spoon";
  int number = 9;
  String noun6 = "Heroine";
  
  System.out.println(story);


  
  
  
  //The template for the story
  String story = "This morning "+name1+" woke up feeling "+adjective1+". 'It is going to be a "+adjective2+" day!' Outside, a bunch of "+noun1+"s were protesting to keep "+noun2+" in stores. They began to "+verb1+" to the rhythm of the "+noun3+", which made all the "+noun4+"s very "+adjective3+". Concerned, "+name1+" texted "+name2+", who flew "+name1+" to "+place1+" and dropped "+name1+" in a puddle of frozen "+noun5+". "+name1+" woke up in the year "+number+", in a world where "+noun6+"s ruled the world.";
}       

}

Welcome to the forums!

Try running your code. You’ll get an error that says the symbol for story cannot be found. Remember that we must always declare variables before using them (otherwise, we’re using them before we create them!). If we want to, as in your case, print out a variable’s value, we should also assign the variable its value before printing it.

Aside: the line where you initialize the template for the story is pretty long. A good rule of thumb is to keep lines to 80 characters or less.

How can you fix the code so that it runs and prints out the expected result?

1 Like

Thank you for the response!

2 Likes

hello, I’am learning for java I don’t understand how to got the good output form this code can somebady help me sorry for my english I speaking rather thanks for your help

 String story = "This morning "+name1+" woke up feeling "+adjective1+". 'It is going to be a "+adjective2+" day!' Outside, a bunch of "+noun1+"s were protesting to keep "+noun2+" in stores. They began to "+verb1+" to the rhythm of the "+noun3+", which made all the "+noun4+"s very "+adjective3+". Concerned, "+name1+" texted "+name2+", who flew "+name1+" to "+place1+" and dropped "+name1+" in a puddle of frozen "+noun5+". "+name1+" woke up in the year "+number+", in a world where "+noun6+"s ruled the world.";

String name1 = “Laura”; String adjective1 = “process”;
String adjective2 = “hit”;
String adjective3 = “eat”;

  String verb1 = "walking";

String noun1 = “Melina”;
String noun2 = “Audrey”;
String noun3 = “Awa”;
String noun4 = “Julien”;
String noun5 = “Assia”;
String noun6 = “Nourah”;

noun2 = “Estelle”;

int number = 25;

String place1 = “soisy”;

System.out.println(name1 + adjective1 + adjective2 + adjective3 + +verb1+ +noun1+ + noun2 + noun3 + noun4 + noun5 + noun6 + noun2 + number + place1)

try
putting this after you declare the other variables (because story uses the those other variables) only.

 String story = "This morning "+name1+" woke up feeling "+adjective1+". 'It is going to be a "+adjective2+" day!' Outside, a bunch of "+noun1+"s were protesting to keep "+noun2+" in stores. They began to "+verb1+" to the rhythm of the "+noun3+", which made all the "+noun4+"s very "+adjective3+". Concerned, "+name1+" texted "+name2+", who flew "+name1+" to "+place1+" and dropped "+name1+" in a puddle of frozen "+noun5+". "+name1+" woke up in the year "+number+", in a world where "+noun6+"s ruled the world.";

and then,

System.out.println(story);

thank very much for the help

Alright I’m officially stumped. What’s up with my code?

Error is MadLibs.java:24: error: ‘;’ expected

a. that’s not the part of the code i wrote. b. why am I getting the error three times?

Hi, welcome to the forums.

Can you re-post your entire program, correctly formatted for the forums, so that I can run it without having to re-type everything? :slight_smile: