Mad libs assignment

ok so im lost as to what it is thats missing ive been racking my head trying to figure out why it wont show the story i get a blank screen when i run it when i leave the System.out.println() blank and when i put System.out.println(story) it gives me an error im so lost did i miss a step somewhere?
public class MadLibs {
/*
This program generates a mad libbed story.
Author: Cristian
Date: 4/24/24
*/
public static void main(String[ ] args){
String name1 = “Joseph Flemming”;
String name2 = “Josiah Dirk”;
String adjective1 = “amazing”;
String adjective2 = “good”;
String adjective3 = “abnormally”;
String noun1 = “women”;
String noun2 = “love”;
String noun3 = “music”;
String verb1 = “sing”;
String place1 = “rome”;
String noun4 = “men”;
String noun5 = “acid”;
String noun6 = “donkeys”;
int number = 2055;
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.";
}       

}

Is Story meant to be a string value, a variable or a function call? We don’t see it being defined anywhere.

it says im supposed to use story as a variable “Time to read the story! Use System.out.println() to print the story variable.”
is what the assignment says when i tried just story its pops up as an error when i put it in quotations it only says story

D’oh! Story is defined, just didn’t see it (too obvious). It should be above your println statement.

Correct me if I’m wrong but this looks like Java.

One thing that isn’t super clear to me is if the String story is below or above the print statement. I’ve seen most coders have a hiarchy when declaring variables. Where you declare them before you use them. So if you want

System.out.println(a+b);
int a = 5;
int b = 2;

returned 3 errors for me, while

int a = 5;
int b = 2;
System.out.println(a+b);

Will print 7, it can get pretty complex but for your problem specifically, the computer is reading line by line. So when try to call the String story, to the computer it dosen’t exist because the information it needs is after the print statement.

I also created a workspace, where you can see exactly what im talking about --It is currently set to throw an error-- the code below it will not

https://www.codecademy.com/workspaces/662dc31efbc6c34f92411085

2 Likes