public class MadLibs {
/*
This program generates a mad libbed story.
Author: Christopher
Date 3/19/2019
*/
public static void main(String[] args){
String name1= "Moto Moto";
String adjective1= "Big";
String adjective2= "Chunky";
String adjective3= "Plumpy";
String verb1 ="Walking";
String noun1= "Hippo";
String noun2= "Giraffe";
String noun3 ="Lion";
String noun4 ="Lemur";
String noun5 ="Penguin";
String noun6 = "Dog";
String name2 ="Gloria";
int number = 69;
String place1 ="Africa";
System.out.println (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.";
}
}
This somehow does not work and gives me a
MadLibs.java:24: error: cannot find symbol
System.out.println (story);
^
symbol: variable story
location: class MadLibs
1 error
error. Can i have some help?
1 Like
Erm, variable ‘story’ is not declared before line 24.
1 Like
Put the system.out.println (story) line under the story
3 Likes
Hi, I’m struggling with number 12 on the list of instructions. It doesn’t tell you how to insert blank space into the story.
1 Like
I have many problem related to mad libs game. There’s no perfect instructions or any video solution for this game. A tutorial would help us better to complete the task. If anyone have solution about how to write the codes for madlibs then reply please.
2 Likes
Hey, did you find a way to complete instruction number 12?
Hello, @argirovskiivan508068.
Welcome to the forum.
Step 12 is simply asking us to add blank lines or ‘whitespace’ to our code in the code editor, so that you can have a friend type the values in your code to be assigned to the variables without being able to see the story
on the screen. Just hit <enter>
on a blank line repeatedly.
Change it from this:
to this:
2 Likes
Hi,
when i say run, all i could see the word stroy.
how do i fix this ?
public class MadLibs {
/*
This program generates a mad libbed story.
Author: Laura
Date: 2/19/2049
*/
public static void main(String[] args){
String name1 = "anmol";
String adjective1 = "the";
String adjective2 = "this";
String adjective3 = "my";
String verb1 = "sleep";
String noun1 = "india";
String noun2 = "several";
String noun3 = "were";
String noun4 = "a tree";
String noun5 = "portugal";
String noun6 = "many";
String name2 = "laura";
String place1 = "dog";
int number =23;
//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");
}
}
Hello, @anmolguggari47015573.
In the last line of code, story
should not be in quotes. When we are referencing a variable, we just type its name. Placing anything inside of quotes makes it a String literal. Placing a String literal inside the ( )
as the argument to the System.out.println()
method causes it to be printed to the screen.
thank you so much , it worked !