generate a code to generate a madlib story (you can make a story with a template and change nouns and etc)
Assistant
Creating a Mad Libs-style story is a fun way to make a program interactive. We'll write a simple Python script that prompts the user for various parts of speech and then inserts those words into a predefined story template. Here’s a basic example to get you started:
python
def madlib():
# Prompting user for inputs
adjective1 = input("Enter an adjective: ")
adjective2 = input("Enter another adjective: ")
noun1 = input("Enter a noun: ")
noun2 = input("Enter another noun: ")
plural_noun = input("Enter a plural noun: ")
game = input("Enter a game: ")
verb_ing = input("Enter a verb ending in 'ing': ")
verb = input("Enter a verb: ")
place = input("Enter a place: ")
food1 = input("Enter a type of food: ")
food2 = input("Enter another type of food: ")
number = input("Enter a number: ")
noun3 = input("Enter one more noun: ")
# Madlib story template
story = f"""
Vacation time is just the best! Last summer, I went to {place} with my {adjective1} family.
We packed our {adjective2} {noun1} and set out on a great adventure. We played {game} every day and
ate lots of {food1} and {food2}. One day, we even went to a {noun2} and saw {number} {plural_noun} {verb_ing}
in the wild. It was so amazing! Before we left, I made sure to {verb} a {noun3} as a souvenir.
"""
# Output the completed story
print(story)
if __name__ == "__main__":
madlib()
Instructions:
Run the Script: When you execute the script, it will prompt you to input different words. These inputs will replace the placeholders in the story template.
Fill in the Blanks: Respond to each prompt with any word that fits the request (e.g., adjective, noun, etc.).
Read the Story: After all inputs are provided, the program will print a complete story with your words filled in.
This basic example uses standard input to collect data from the user. You can expand on the template by adding more variables or making the story more complex. Have fun experimenting and coming up with creative stories!
User
make it java
Assistant
Sure, here's a simple Java program to create a Mad Libs-style story. The program will prompt the user to enter various parts of speech, then insert them into a predefined story template and display the result.
java
import java.util.Scanner;
public class MadLibs {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompting user for inputs
System.out.print("Enter an adjective: ");
String adjective1 = scanner.nextLine();
System.out.print("Enter another adjective: ");
String adjective2 = scanner.nextLine();
System.out.print("Enter a noun: ");
String noun1 = scanner.nextLine();
System.out.print("Enter another noun: ");
String noun2 = scanner.nextLine();
System.out.print("Enter a plural noun: ");
String pluralNoun = scanner.nextLine();
System.out.print("Enter a game: ");
String game = scanner.nextLine();
System.out.print("Enter a verb ending in 'ing': ");
String verbIng = scanner.nextLine();
System.out.print("Enter a verb: ");
String verb = scanner.nextLine();
System.out.print("Enter a place: ");
String place = scanner.nextLine();
System.out.print("Enter a type of food: ");
String food1 = scanner.nextLine();
System.out.print("Enter another type of food: ");
String food2 = scanner.nextLine();
System.out.print("Enter a number: ");
String number = scanner.nextLine();
System.out.print("Enter one more noun: ");
String noun3 = scanner.nextLine();
// Madlib story template
String story = String.format(
"\nVacation time is just the best! Last summer, I went to %s with my %s family. " +
"We packed our %s %s and set out on a great adventure. We played %s every day and " +
"ate lots of %s and %s. One day, we even went to a %s and saw %s %s %s in the wild. It was so amazing! " +
"Before we left, I made sure to %s a %s as a souvenir.",
place, adjective1, adjective2, noun1, game, food1, food2, noun2, number, pluralNoun, verbIng, verb, noun3);
// Output the completed story
System.out.println(story);
scanner.close();
}
}
User
make the file name Main.java
Assistant
Certainly! To create a Java program with the name Main.java, you can use the following code. This code does the same as before: it prompts the user for various parts of speech, inserts those words into a predefined story template, and prints the result.
Here's how you can do it:
Create a file named Main.java and add the following code:
java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompting user for inputs
System.out.print("Enter an adjective: ");
String adjective1 = scanner.nextLine();
System.out.print("Enter another adjective: ");
String adjective2 = scanner.nextLine();
System.out.print("Enter a noun: ");
String noun1 = scanner.nextLine();
System.out.print("Enter another noun: ");
String noun2 = scanner.nextLine();
System.out.print("Enter a plural noun: ");
String pluralNoun = scanner.nextLine();
System.out.print("Enter a game: ");
String game = scanner.nextLine();
System.out.print("Enter a verb ending in 'ing': ");
String verbIng = scanner.nextLine();
System.out.print("Enter a verb: ");
String verb = scanner.nextLine();
System.out.print("Enter a place: ");
String place = scanner.nextLine();
System.out.print("Enter a type of food: ");
String food1 = scanner.nextLine();
System.out.print("Enter another type of food: ");
String food2 = scanner.nextLine();
System.out.print("Enter a number: ");
String number = scanner.nextLine();
System.out.print("Enter one more noun: ");
String noun3 = scanner.nextLine();
// Madlib story template
String story = String.format(
"\nVacation time is just the best! Last summer, I went to %s with my %s family. " +
"We packed our %s %s and set out on a great adventure. We played %s every day and " +
"ate lots of %s and %s. One day, we even went to a %s and saw %s %s %s in the wild. It was so amazing! " +
"Before we left, I made sure to %s a %s as a souvenir.",
place, adjective1, adjective2, noun1, game, food1, food2, noun2, number, pluralNoun, verbIng, verb, noun3);
// Output the completed story
System.out.println(story);
scanner.close();
}
}
User
make it this: 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.";
Assistant
Certainly! I'll create a Java program based on the new Mad Libs story template you provided. This program will prompt the user to enter various parts of speech and other required inputs, then it will generate the story using those inputs.
Here's the complete program in Java:
java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompting user for inputs
System.out.print("Enter a name: ");
String name1 = scanner.nextLine();
System.out.print("Enter an adjective: ");
String adjective1 = scanner.nextLine();
System.out.print("Enter another adjective: ");
String adjective2 = scanner.nextLine();
System.out.print("Enter a noun: ");
String noun1 = scanner.nextLine();
System.out.print("Enter another noun: ");
String noun2 = scanner.nextLine();
System.out.print("Enter a verb: ");
String verb1 = scanner.nextLine();
System.out.print("Enter one more noun: ");
String noun3 = scanner.nextLine();
System.out.print("Enter yet another noun: ");
String noun4 = scanner.nextLine();
System.out.print("Enter another adjective: ");
String adjective3 = scanner.nextLine();
System.out.print("Enter another name: ");
String name2 = scanner.nextLine();
System.out.print("Enter a place: ");
String place1 = scanner.nextLine();
System.out.print("Enter a final noun: ");
String noun5 = scanner.nextLine();
System.out.print("Enter a number: ");
String number = scanner.nextLine();
System.out.print("Enter a last noun: ");
String noun6 = scanner.nextLine();
// Madlib story template
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.";
// Output the completed story
System.out.println(story);
scanner.close();
}
}
User
make it an app
Assistant
Creating a Java application with a graphical user interface (GUI) for your Mad Libs story can enhance the user experience. You can use Java's Swing library to create a simple GUI application. Here’s how you can refactor your console application into a GUI application:
Step-by-Step Guide
1. Import Required Packages
You'll need to import the necessary classes from the Swing library to build the GUI.
2. Set Up the JFrame
Create a main window (JFrame) to hold components like JTextField for input and a JButton to generate the story.
3. Add Components
Use JTextFields to get user inputs and a JButton to trigger story generation. The resulting story can be displayed in a JTextArea.
4. Action Listener
Implement an ActionListener that constructs the story when the button is pressed and outputs it to a JTextArea.
Here's a simple implementation:
java
User
make it more visually appealing (white background, and make the question appear in the center, make the button look black and white and etc.)
Assistant
Certainly! You can use Swing's layout managers and component customization options to enhance the visual appeal of your Mad Libs GUI application. Here’s an enhanced version of the previous implementation with visual improvements:
java
User
undo
Assistant
If you want to revert to the more straightforward version of the Java GUI application without the additional styling and layout changes, you can use a simpler implementation. This version keeps the basic functionality while minimizing customization, making it easier to manage and understand.
Here's the original, less-stylized version using Java's Swing library:
java
User
can you use css with java?
Assistant
Java itself does not natively support CSS like web technologies do, but you can achieve similar styling for Java applications, particularly when dealing with JavaFX. JavaFX, a popular framework for building rich client applications in Java, supports CSS-like styling for its components.
Using CSS with JavaFX
JavaFX allows you to use a subset of CSS to style UI components in a more web-like fashion. This feature helps you separate the presentation layer from the application logic and makes it easier to maintain and switch designs.
Here's a simple example of how you might use CSS with a JavaFX application:
Step-by-Step Example
Create a JavaFX Application: Set up a simple JavaFX application.
Create a CSS File: Define styles in a separate CSS file.
Apply the CSS: Load and apply the CSS file to JavaFX components.
Example
Main.java: The JavaFX application
java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX with CSS Example");
// Create JavaFX components
Label label = new Label("Hello, JavaFX!");
Button button = new Button("Click Me!");
VBox vbox = new VBox(10, label, button);
vbox.setStyle("-fx-padding: 10; -fx-alignment: center;");
// Create a scene and add the CSS
Scene scene = new Scene(vbox, 300, 200);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
User
do the matlib again
Assistant
Certainly! Let's create a JavaFX application for the Mad Libs story you provided. This application will allow users to enter various words through a graphical interface, and it will style components using JavaFX's CSS capabilities.
Directory Structure
Main.java - The main JavaFX application.
style.css - The CSS file for styling the application.
Main.java
java
User
remove the javaFx
Assistant
Sure! Let’s revert back to a simpler, console-based Java program for the Mad Libs story without using JavaFX. This version will prompt the user for input in the console and print out the finished story. This approach relies purely on standard Java libraries to handle input and output.
Here's how you can implement a basic console-based version:
java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Prompting the user for inputs
System.out.print("Enter a name: ");
String name1 = scanner.nextLine();
System.out.print("Enter an adjective: ");
String adjective1 = scanner.nextLine();
System.out.print("Enter another adjective: ");
String adjective2 = scanner.nextLine();
System.out.print("Enter a noun: ");
String noun1 = scanner.nextLine();
System.out.print("Enter another noun: ");
String noun2 = scanner.nextLine();
System.out.print("Enter a verb: ");
String verb1 = scanner.nextLine();
System.out.print("Enter one more noun: ");
String noun3 = scanner.nextLine();
System.out.print("Enter yet another noun: ");
String noun4 = scanner.nextLine();
System.out.print("Enter another adjective: ");
String adjective3 = scanner.nextLine();
System.out.print("Enter another name: ");
String name2 = scanner.nextLine();
System.out.print("Enter a place: ");
String place1 = scanner.nextLine();
System.out.print("Enter a final noun: ");
String noun5 = scanner.nextLine();
System.out.print("Enter a number: ");
String number = scanner.nextLine();
System.out.print("Enter a last noun: ");
String noun6 = scanner.nextLine();
// Constructing the Mad Libs 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.";
// Output the completed story
System.out.println("\nHere's your Mad Libs story:\n");
System.out.println(story);
scanner.close();
}
}
User
make it look more fun and funny and visually appealing
Assistant
Creating a visually appealing and fun console-based application can be a bit challenging since console applications are text-based and have limited styling capabilities compared to GUI frameworks. However, we can enhance the user experience by incorporating ASCII art, using colorful text, and formatting output to make it more engaging and easy to read.
To add color to your console application, you can use ANSI escape codes, which are sequences of characters that modify the text output (e.g., changing colors). Keep in mind that this may not work in all terminals, but most modern terminals support it.
Below is an enhanced version of the Mad Libs console application with some added personality:
java
User
make it more mature
Assistant
Certainly! We can adjust the language and tone of the Mad Libs game to suit a more mature audience while still keeping it engaging. Here's how you might present a version that's designed for adults, perhaps with a more sophisticated or adventurous storyline:
java
User
don't change the template and make it more fun
Assistant
Certainly! Let's keep the original Mad Libs template you provided while making it more enjoyable with creative prompts and colorful text. We will maintain a playful tone without altering the story template structure. Here's how you can do it:
java
User
give an example of what the story'll say and make the template alan becker stickfigure themed.
Assistant
Let's craft a Mad Libs-style story with an Alan Becker stick figure theme. Alan Becker is well-known for his stick figure animations, so we'll incorporate elements from his animations to make the story fit the theme.
Template Adaptation:
We'll use elements like "stick figures," "animation wars," "digital canvases," and other Alan Becker-related themes. Here's how you might fill it out:
Example Word Choices:
Name1: Alan
Adjective1: adventurous
Adjective2: animated
Noun1: stick figure
Noun2: cursor
Verb1: draw
Noun3: command prompt
Noun4: toolbar
Adjective3: chaotic
Name2: The Chosen One
Place1: digital arena
Noun5: pixel
Number: 2023
Noun6: frame
Example Story:
plaintext
This morning Alan woke up feeling adventurous. 'It is going to be an animated day!' Outside, a bunch of stick figures were protesting to keep cursors in stores. They began to draw to the rhythm of the command prompt, which made all the toolbars very chaotic. Concerned, Alan texted The Chosen One, who flew Alan to the digital arena and dropped Alan in a puddle of frozen pixels. Alan woke up in the year 2023, in a world where frames ruled the world.
Revised Code with Themed Prompts:
Here's how the program could look with these themed prompts:
java
User
make it give an example of what the verb noun or adjective'll say in the story
Assistant
To make the application more user-friendly and provide a hint or example of what type of word might fit well in the story, we can include sample words as part of the prompts. This will guide users to choose words suited to the story context, especially for those unfamiliar with adjectives, nouns, or verbs.
Here's the enhanced version of the Mad Libs program with examples included in the prompts:
java
User
make it an example of what it'll look like in the story (name: TSC, example: This morning [name] woke up..)
Assistant
Certainly! Let's adjust the prompts in the Mad Libs program so that each prompt not only suggests a suitable word type via examples but also illustrates how that word will appear in the story. This contextual approach can help users make more informed and creative choices.
Here's how the enhanced program looks:
java
Not yet included in a published release.
Instructions:
Compile and Run the Program: Use a Java development environment to compile and run the program.
Provide Inputs: As the program runs, it will prompt you for various parts of speech or other words.
Read the Story: After all required inputs are provided, the program will print out a completed Mad Libs story featuring your inputs.
This example uses the Scanner class to read input from the user. The program then utilizes String.format to insert user-provided words into the designated spots in the story template. Feel free to modify the template or expand with more dynamic inputs for more intricate stories!
Instructions:
Save the File: Save the above code into a file named Main.java.
Compile the Program: Open a terminal or command prompt, navigate to the directory containing your Main.java file, and compile the program using:
bash
javac Main.java
Run the Program: After compiling, run the program with:
bash
java Main
Provide Inputs: Follow the prompts to enter the required words.
Read the Story: The program will output a complete story with your inputs inserted into the template.
This setup is straightforward and should work well if you follow these steps. It's a basic Mad Libs Java example that you can expand upon as needed!
Instructions:
Save the File: Save the above code into a file named Main.java.
Compile and Run the Program:
Open a terminal or command prompt.
Navigate to the directory containing your Main.java file.
Compile the program with: javac Main.java
Run the compiled program with: java Main
Follow Prompts: Enter the requested words as prompted by the program.
Read the Story: The program will output a personalized Mad Libs story using your inputs.
This program makes use of Java's Scanner class to capture user input and then constructs the story using string concatenation. It's a straightforward way to create interactive content. Feel free to expand or modify the story to make it even more fun!
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MadLibsApp {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("Mad Libs Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 600);
frame.setLayout(new GridLayout(15, 2));
// Input fields
JTextField name1Field = new JTextField();
JTextField adjective1Field = new JTextField();
JTextField adjective2Field = new JTextField();
JTextField noun1Field = new JTextField();
JTextField noun2Field = new JTextField();
JTextField verb1Field = new JTextField();
JTextField noun3Field = new JTextField();
JTextField noun4Field = new JTextField();
JTextField adjective3Field = new JTextField();
JTextField name2Field = new JTextField();
JTextField place1Field = new JTextField();
JTextField noun5Field = new JTextField();
JTextField numberField = new JTextField();
JTextField noun6Field = new JTextField();
// Adding components to the frame
frame.add(new JLabel("Enter a name:"));
frame.add(name1Field);
frame.add(new JLabel("Enter an adjective:"));
frame.add(adjective1Field);
frame.add(new JLabel("Enter another adjective:"));
frame.add(adjective2Field);
frame.add(new JLabel("Enter a noun:"));
frame.add(noun1Field);
frame.add(new JLabel("Enter another noun:"));
frame.add(noun2Field);
frame.add(new JLabel("Enter a verb:"));
frame.add(verb1Field);
frame.add(new JLabel("Enter one more noun:"));
frame.add(noun3Field);
frame.add(new JLabel("Enter yet another noun:"));
frame.add(noun4Field);
frame.add(new JLabel("Enter another adjective:"));
frame.add(adjective3Field);
frame.add(new JLabel("Enter another name:"));
frame.add(name2Field);
frame.add(new JLabel("Enter a place:"));
frame.add(place1Field);
frame.add(new JLabel("Enter a final noun:"));
frame.add(noun5Field);
frame.add(new JLabel("Enter a number:"));
frame.add(numberField);
frame.add(new JLabel("Enter a last noun:"));
frame.add(noun6Field);
JButton generateButton = new JButton("Generate Story");
JTextArea storyArea = new JTextArea();
storyArea.setWrapStyleWord(true);
storyArea.setLineWrap(true);
storyArea.setEditable(false);
frame.add(generateButton);
frame.add(new JScrollPane(storyArea));
generateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String story = "This morning " + name1Field.getText() + " woke up feeling " + adjective1Field.getText() +
". 'It is going to be a " + adjective2Field.getText() + " day!' Outside, a bunch of " + noun1Field.getText() +
"s were protesting to keep " + noun2Field.getText() + " in stores. They began to " + verb1Field.getText() +
" to the rhythm of the " + noun3Field.getText() + ", which made all the " + noun4Field.getText() +
"s very " + adjective3Field.getText() + ". Concerned, " + name1Field.getText() + " texted " + name2Field.getText() +
", who flew " + name1Field.getText() + " to " + place1Field.getText() + " and dropped " + name1Field.getText() +
" in a puddle of frozen " + noun5Field.getText() + ". " + name1Field.getText() + " woke up in the year " +
numberField.getText() + ", in a world where " + noun6Field.getText() + "'s ruled the world.";
storyArea.setText(story);
}
});
frame.setVisible(true);
});
}
}
Instructions to Run the Application:
Create a New Java File: Save the above code into a file named MadLibsApp.java.
Compile and Run:
Compile the program using: javac MadLibsApp.java
Run the program with: java MadLibsApp
Fill in the Inputs: Use the GUI inputs to enter your words.
Generate the Story: Click the "Generate Story" button to see the final story in the text area.
This application uses Java's Swing library to create a simple user interface where users can enter their inputs and generate a fun story with the press of a button. Feel free to customize the layout and style to better fit your needs!
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MadLibsApp {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("Mad Libs Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 700);
frame.setLayout(new BorderLayout());
// Set background color
JPanel mainPanel = new JPanel(new GridBagLayout());
mainPanel.setBackground(Color.WHITE);
frame.add(mainPanel, BorderLayout.CENTER);
// Create GridBagConstraints
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
gbc.gridx = 0;
gbc.gridy = GridBagConstraints.RELATIVE;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.CENTER;
// Input fields
JTextField name1Field = createTextField();
JTextField adjective1Field = createTextField();
JTextField adjective2Field = createTextField();
JTextField noun1Field = createTextField();
JTextField noun2Field = createTextField();
JTextField verb1Field = createTextField();
JTextField noun3Field = createTextField();
JTextField noun4Field = createTextField();
JTextField adjective3Field = createTextField();
JTextField name2Field = createTextField();
JTextField place1Field = createTextField();
JTextField noun5Field = createTextField();
JTextField numberField = createTextField();
JTextField noun6Field = createTextField();
// Add labels and fields to the panel
addComponent(mainPanel, createLabel("Enter a name:"), gbc);
addComponent(mainPanel, name1Field, gbc);
addComponent(mainPanel, createLabel("Enter an adjective:"), gbc);
addComponent(mainPanel, adjective1Field, gbc);
addComponent(mainPanel, createLabel("Enter another adjective:"), gbc);
addComponent(mainPanel, adjective2Field, gbc);
addComponent(mainPanel, createLabel("Enter a noun:"), gbc);
addComponent(mainPanel, noun1Field, gbc);
addComponent(mainPanel, createLabel("Enter another noun:"), gbc);
addComponent(mainPanel, noun2Field, gbc);
addComponent(mainPanel, createLabel("Enter a verb:"), gbc);
addComponent(mainPanel, verb1Field, gbc);
addComponent(mainPanel, createLabel("Enter one more noun:"), gbc);
addComponent(mainPanel, noun3Field, gbc);
addComponent(mainPanel, createLabel("Enter yet another noun:"), gbc);
addComponent(mainPanel, noun4Field, gbc);
addComponent(mainPanel, createLabel("Enter another adjective:"), gbc);
addComponent(mainPanel, adjective3Field, gbc);
addComponent(mainPanel, createLabel("Enter another name:"), gbc);
addComponent(mainPanel, name2Field, gbc);
addComponent(mainPanel, createLabel("Enter a place:"), gbc);
addComponent(mainPanel, place1Field, gbc);
addComponent(mainPanel, createLabel("Enter a final noun:"), gbc);
addComponent(mainPanel, noun5Field, gbc);
addComponent(mainPanel, createLabel("Enter a number:"), gbc);
addComponent(mainPanel, numberField, gbc);
addComponent(mainPanel, createLabel("Enter a last noun:"), gbc);
addComponent(mainPanel, noun6Field, gbc);
JButton generateButton = new JButton("Generate Story");
customizeButton(generateButton);
JTextArea storyArea = new JTextArea(5, 40);
storyArea.setWrapStyleWord(true);
storyArea.setLineWrap(true);
storyArea.setEditable(false);
storyArea.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JScrollPane scrollPane = new JScrollPane(storyArea);
scrollPane.setPreferredSize(new Dimension(500, 100));
JPanel bottomPanel = new JPanel();
bottomPanel.setBackground(Color.WHITE);
bottomPanel.add(generateButton);
bottomPanel.add(scrollPane);
frame.add(mainPanel, BorderLayout.NORTH);
frame.add(bottomPanel, BorderLayout.SOUTH);
generateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String story = "This morning " + name1Field.getText() + " woke up feeling " + adjective1Field.getText() +
". 'It is going to be a " + adjective2Field.getText() + " day!' Outside, a bunch of " + noun1Field.getText() +
"s were protesting to keep " + noun2Field.getText() + " in stores. They began to " + verb1Field.getText() +
" to the rhythm of the " + noun3Field.getText() + ", which made all the " + noun4Field.getText() +
"s very " + adjective3Field.getText() + ". Concerned, " + name1Field.getText() + " texted " + name2Field.getText() +
", who flew " + name1Field.getText() + " to " + place1Field.getText() + " and dropped " + name1Field.getText() +
" in a puddle of frozen " + noun5Field.getText() + ". " + name1Field.getText() + " woke up in the year " +
numberField.getText() + ", in a world where " + noun6Field.getText() + "'s ruled the world.";
storyArea.setText(story);
}
});
frame.setVisible(true);
});
}
private static JTextField createTextField() {
JTextField textField = new JTextField(15);
textField.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
return textField;
}
private static JLabel createLabel(String text) {
JLabel label = new JLabel(text);
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setPreferredSize(new Dimension(200, 25));
return label;
}
private static void addComponent(JPanel panel, Component component, GridBagConstraints gbc) {
panel.add(component, gbc);
}
private static void customizeButton(JButton button) {
button.setBackground(Color.BLACK);
button.setForeground(Color.WHITE);
button.setFocusPainted(false);
button.setBorder(BorderFactory.createLineBorder(Color.BLACK));
button.setPreferredSize(new Dimension(180, 30));
}
}
Customization Highlights:
White Background: Sets the background color of the main panel and bottom panel to white for a clean look.
Centered Labels: All labels are centered using SwingConstants.CENTER.
Black and White Button: The JButton is customized with a black background and white text for a classic look. It also features a simple line border and specified dimensions.
Layout and Alignment:
The main panel uses GridBagLayout for centering components. This layout manager allows for flexible component arrangement.
Insets are used to add space between components, keeping the layout neat.
Text Areas: The story text area is wrapped in a JScrollPane to handle long stories that would otherwise overflow the visible area.
Running the Application:
Compile and run this program in the same manner as regular Java applications using Swing. The application will now have a more visually appealing interface conducive to engaging users:
Save the code in MadLibsApp.java.
Compile: javac MadLibsApp.java.
Run the application with: java MadLibsApp.
This setup creates a user-friendly interface where users can input their text and see the resulting story in a neat and attractive format. Adjust component sizes and colors as necessary to fit specific aesthetic preferences or functional requirements.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MadLibsApp {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("Mad Libs Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 600);
frame.setLayout(new GridLayout(15, 2));
// Input fields
JTextField name1Field = new JTextField();
JTextField adjective1Field = new JTextField();
JTextField adjective2Field = new JTextField();
JTextField noun1Field = new JTextField();
JTextField noun2Field = new JTextField();
JTextField verb1Field = new JTextField();
JTextField noun3Field = new JTextField();
JTextField noun4Field = new JTextField();
JTextField adjective3Field = new JTextField();
JTextField name2Field = new JTextField();
JTextField place1Field = new JTextField();
JTextField noun5Field = new JTextField();
JTextField numberField = new JTextField();
JTextField noun6Field = new JTextField();
// Adding components to the frame
frame.add(new JLabel("Enter a name:"));
frame.add(name1Field);
frame.add(new JLabel("Enter an adjective:"));
frame.add(adjective1Field);
frame.add(new JLabel("Enter another adjective:"));
frame.add(adjective2Field);
frame.add(new JLabel("Enter a noun:"));
frame.add(noun1Field);
frame.add(new JLabel("Enter another noun:"));
frame.add(noun2Field);
frame.add(new JLabel("Enter a verb:"));
frame.add(verb1Field);
frame.add(new JLabel("Enter one more noun:"));
frame.add(noun3Field);
frame.add(new JLabel("Enter yet another noun:"));
frame.add(noun4Field);
frame.add(new JLabel("Enter another adjective:"));
frame.add(adjective3Field);
frame.add(new JLabel("Enter another name:"));
frame.add(name2Field);
frame.add(new JLabel("Enter a place:"));
frame.add(place1Field);
frame.add(new JLabel("Enter a final noun:"));
frame.add(noun5Field);
frame.add(new JLabel("Enter a number:"));
frame.add(numberField);
frame.add(new JLabel("Enter a last noun:"));
frame.add(noun6Field);
JButton generateButton = new JButton("Generate Story");
JTextArea storyArea = new JTextArea();
storyArea.setWrapStyleWord(true);
storyArea.setLineWrap(true);
storyArea.setEditable(false);
frame.add(generateButton);
frame.add(new JScrollPane(storyArea));
generateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String story = "This morning " + name1Field.getText() + " woke up feeling " + adjective1Field.getText() +
". 'It is going to be a " + adjective2Field.getText() + " day!' Outside, a bunch of " + noun1Field.getText() +
"s were protesting to keep " + noun2Field.getText() + " in stores. They began to " + verb1Field.getText() +
" to the rhythm of the " + noun3Field.getText() + ", which made all the " + noun4Field.getText() +
"s very " + adjective3Field.getText() + ". Concerned, " + name1Field.getText() + " texted " + name2Field.getText() +
", who flew " + name1Field.getText() + " to " + place1Field.getText() + " and dropped " + name1Field.getText() +
" in a puddle of frozen " + noun5Field.getText() + ". " + name1Field.getText() + " woke up in the year " +
numberField.getText() + ", in a world where " + noun6Field.getText() + "'s ruled the world.";
storyArea.setText(story);
}
});
frame.setVisible(true);
});
}
}
Running the Application:
Save the Code: Make sure the file is named MadLibsApp.java.
Compile the Program:
Use the command: javac MadLibsApp.java
Run the Program:
Execute: java MadLibsApp
This application retains the core functionality with a straightforward graphical user interface without additional styling elements. It uses basic Swing components and a grid layout to organize inputs and outputs neatly within the frame.
Directory Structure: Ensure that the CSS file (style.css) is in the same directory as your compiled Java class files, or adjust the getResource path accordingly.
Compile: Compile your JavaFX application:
bash
javac Main.java
Run: Execute the application:
bash
java Main
Notes:
Scene Stylesheets: You can add CSS files to a JavaFX Scene using the getStylesheets().add() method.
CSS Rules: JavaFX CSS offers many features similar to web CSS, such as styling properties for fonts, colors, padding, borders, and more.
Flexibility: CSS in JavaFX allows for dynamic changes, enabling developers to switch themes at runtime.
JavaFX with CSS can provide enhanced control over the look-and-feel of Java applications, making them visually appealing without deeply embedding style logic in the Java code. This separation of concerns is a key benefit of using CSS with JavaFX.
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Mad Libs Game");
// Text fields for user input
TextField name1Field = new TextField();
TextField adjective1Field = new TextField();
TextField adjective2Field = new TextField();
TextField noun1Field = new TextField();
TextField noun2Field = new TextField();
TextField verb1Field = new TextField();
TextField noun3Field = new TextField();
TextField noun4Field = new TextField();
TextField adjective3Field = new TextField();
TextField name2Field = new TextField();
TextField place1Field = new TextField();
TextField noun5Field = new TextField();
TextField numberField = new TextField();
TextField noun6Field = new TextField();
// Layout grid for input fields
GridPane grid = new GridPane();
grid.setPadding(new Insets(10));
grid.setVgap(10);
grid.setHgap(10);
// Adding labels and input fields to the grid
grid.add(new Label("Enter a name:"), 0, 0);
grid.add(name1Field, 1, 0);
grid.add(new Label("Enter an adjective:"), 0, 1);
grid.add(adjective1Field, 1, 1);
grid.add(new Label("Enter another adjective:"), 0, 2);
grid.add(adjective2Field, 1, 2);
grid.add(new Label("Enter a noun:"), 0, 3);
grid.add(noun1Field, 1, 3);
grid.add(new Label("Enter another noun:"), 0, 4);
grid.add(noun2Field, 1, 4);
grid.add(new Label("Enter a verb:"), 0, 5);
grid.add(verb1Field, 1, 5);
grid.add(new Label("Enter one more noun:"), 0, 6);
grid.add(noun3Field, 1, 6);
grid.add(new Label("Enter yet another noun:"), 0, 7);
grid.add(noun4Field, 1, 7);
grid.add(new Label("Enter another adjective:"), 0, 8);
grid.add(adjective3Field, 1, 8);
grid.add(new Label("Enter another name:"), 0, 9);
grid.add(name2Field, 1, 9);
grid.add(new Label("Enter a place:"), 0, 10);
grid.add(place1Field, 1, 10);
grid.add(new Label("Enter a final noun:"), 0, 11);
grid.add(noun5Field, 1, 11);
grid.add(new Label("Enter a number:"), 0, 12);
grid.add(numberField, 1, 12);
grid.add(new Label("Enter a last noun:"), 0, 13);
grid.add(noun6Field, 1, 13);
// Button and story area
Button generateButton = new Button("Generate Story");
TextArea storyArea = new TextArea();
storyArea.setWrapText(true);
storyArea.setEditable(false);
// Event handling for button click
generateButton.setOnAction(e -> {
String story = "This morning " + name1Field.getText() + " woke up feeling " + adjective1Field.getText() +
". 'It is going to be a " + adjective2Field.getText() + " day!' Outside, a bunch of " + noun1Field.getText() +
"s were protesting to keep " + noun2Field.getText() + " in stores. They began to " + verb1Field.getText() +
" to the rhythm of the " + noun3Field.getText() + ", which made all the " + noun4Field.getText() +
"s very " + adjective3Field.getText() + ". Concerned, " + name1Field.getText() + " texted " + name2Field.getText() +
", who flew " + name1Field.getText() + " to " + place1Field.getText() + " and dropped " + name1Field.getText() +
" in a puddle of frozen " + noun5Field.getText() + ". " + name1Field.getText() + " woke up in the year " +
numberField.getText() + ", in a world where " + noun6Field.getText() + "'s ruled the world.";
storyArea.setText(story);
});
// Main layout
VBox vbox = new VBox(10, grid, generateButton, storyArea);
vbox.setPadding(new Insets(10));
// Scene setup
Scene scene = new Scene(vbox, 600, 800);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Project Structure: Make sure Main.java and style.css are in the appropriate directories so they can reference each other correctly (style.css should be in the same directory as or in a resources directory accessible by Main.java).
Compile and Launch:
Compile the JavaFX code:
bash
javac Main.java
Run the application:
bash
java Main
Interact with the App: Use the application interface to enter words. Click the "Generate Story" button to see your custom Mad Libs story appear in the text area.
This setup allows you to visually style the application more effectively using CSS while keeping the logic and the UI clearly separated. JavaFX's support for CSS makes it easier to maintain a neat and visually appealing look for desktop applications.
Instructions for Execution:
Save the File: Save the above code as Main.java.
Compile the Program:
Open a terminal or command prompt.
Navigate to the directory containing Main.java.
Compile the code with the command:
bash
javac Main.java
Run the Program:
Execute the program using:
bash
java Main
Input Data: Follow the prompts in the console to enter various words corresponding to the parts of speech or types requested.
Read the Story: After entering all the inputs, the console will display your custom Mad Libs story.
This approach is straightforward and relies entirely on standard input and output through the console. It is an accessible way to create and run a simple interactive Java program without dealing with graphical user interfaces.
import java.util.Scanner;
public class Main {
// ANSI escape codes for text color
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
public static final String WHITE = "\u001B[37m";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println(GREEN + "Welcome to the Fun and Wild Mad Libs Adventure!" + RESET);
System.out.println("Let's create a crazy story together!\n");
// Prompt the user for inputs with colorful and funny prompts
System.out.print(RED + "Enter a funny name: " + RESET);
String name1 = scanner.nextLine();
System.out.print(BLUE + "Enter an adjective (the weirder, the better!): " + RESET);
String adjective1 = scanner.nextLine();
System.out.print(PURPLE + "Enter another adjective (go wild!): " + RESET);
String adjective2 = scanner.nextLine();
System.out.print(CYAN + "Enter a noun (something silly): " + RESET);
String noun1 = scanner.nextLine();
System.out.print(YELLOW + "Enter another noun (the crazier, the better!): " + RESET);
String noun2 = scanner.nextLine();
System.out.print(WHITE + "Enter a verb (be creative!): " + RESET);
String verb1 = scanner.nextLine();
System.out.print(RED + "Enter one more noun (make it funny!): " + RESET);
String noun3 = scanner.nextLine();
System.out.print(BLUE + "Enter yet another noun (get laughable!): " + RESET);
String noun4 = scanner.nextLine();
System.out.print(PURPLE + "Enter another adjective (go bananas!): " + RESET);
String adjective3 = scanner.nextLine();
System.out.print(CYAN + "Enter another funny name: " + RESET);
String name2 = scanner.nextLine();
System.out.print(YELLOW + "Enter an epic place (fantastical!): " + RESET);
String place1 = scanner.nextLine();
System.out.print(WHITE + "Enter a final noun (just hilarious!): " + RESET);
String noun5 = scanner.nextLine();
System.out.print(RED + "Enter a ridiculous number: " + RESET);
String number = scanner.nextLine();
System.out.print(BLUE + "Enter a last noun (absolutely nuts!): " + RESET);
String noun6 = scanner.nextLine();
System.out.println("\n" + GREEN + "Hold on to your hats, here comes your story..." + RESET);
// Constructing the Mad Libs 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.";
// Output the completed story with colors
System.out.println("\n" + CYAN + "Here's your Mad Libs story:\n" + RESET + story);
scanner.close();
}
}
Tips for running:
Save the Code: Save it in a file named Main.java.
Compile and Run:
Compile with javac Main.java
Run using java Main
Features of the Code:
Colorful Text: Uses ANSI escape codes to provide colorful prompts and story output.
Funny Prompts: Each input prompt is designed to elicit fun, silly word choices.
Formatted Output: The program provides a fun intro and uses colors to enhance the reading experience.
Keep in mind that ANSI color codes might not work in all terminal environments (especially on some Windows consoles without proper configuration), so test it in your terminal to ensure compatibility. If the colors don't appear as expected, consider using a terminal or command prompt that supports ANSI escape codes.
import java.util.Scanner;
public class Main {
// ANSI escape codes for text color
public static final String RESET = "\u001B[0m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println(GREEN + "Welcome to the Sophisticated Mad Libs Adventure!" + RESET);
System.out.println("Craft your story with a touch of elegance and imagination.\n");
// Prompting the user for inputs with a refined tone
System.out.print("Enter a name: ");
String name1 = scanner.nextLine();
System.out.print("Enter an adjective to describe a mood: ");
String adjective1 = scanner.nextLine();
System.out.print("Enter an adjective that denotes grandeur: ");
String adjective2 = scanner.nextLine();
System.out.print("Enter a noun representing a social cause: ");
String noun1 = scanner.nextLine();
System.out.print("Enter a noun symbolizing prosperity: ");
String noun2 = scanner.nextLine();
System.out.print("Enter a verb that indicates discernment: ");
String verb1 = scanner.nextLine();
System.out.print("Enter a noun that evokes elegance: ");
String noun3 = scanner.nextLine();
System.out.print("Enter another noun suggesting timelessness: ");
String noun4 = scanner.nextLine();
System.out.print("Enter an adjective that speaks of wisdom: ");
String adjective3 = scanner.nextLine();
System.out.print("Enter another name: ");
String name2 = scanner.nextLine();
System.out.print("Enter a prestigious place: ");
String place1 = scanner.nextLine();
System.out.print("Enter a noun that reflects luxury: ");
String noun5 = scanner.nextLine();
System.out.print("Enter a significant year: ");
String number = scanner.nextLine();
System.out.print("Enter a noun that embodies authority: ");
String noun6 = scanner.nextLine();
System.out.println("\n" + CYAN + "Crafting your narrative masterpiece..." + RESET);
// Constructing the Mad Libs story
String story = String.format(
"In the early hours of the day, %s awoke feeling %s. Today promised to be a truly %s day. " +
"Outside, a gathering of %s enthusiasts campaigned to uphold the availability of %s. " +
"They began to %s in sync with the harmony of the %s, a spectacle that rendered all the %s " +
"individuals around them quite %s. Intrigued, %s reached out to %s, who graciously invited %s " +
"to %s. Upon arrival, %s found themselves immersed in an expanse of frozen %s. " +
"Suddenly, %s was transported to the year %s, a time when %ss governed the realm.",
name1, adjective1, adjective2, noun1, noun2, verb1, noun3, noun4, adjective3, name1, name2, name1,
place1, name1, noun5, name1, number, noun6);
// Output the completed story with refined color emphasis
System.out.println("\n" + YELLOW + "Here's your crafted Mad Libs story:\n" + RESET + story);
scanner.close();
}
}
Details of the Mature Version:
Refined Language: The prompts and story have been revised to use more sophisticated and contemplative language.
Format and Structure: The story is crafted to tell a more nuanced tale, with a sense of adventure and introspection.
Color and Presentation: Uses ANSI color codes for styled output, adding a touch of elegance to the presentation. It maintains a balance by avoiding overly flashy colors.
Instructions for Execution:
Save the file as Main.java.
Compile with javac Main.java.
Run using java Main.
This version aims to engage a more mature audience by focusing on narrative, elegance, and reflective language, while still retaining the interactive and creative essence of a classic Mad Libs experience.
import java.util.Scanner;
public class Main {
// ANSI escape codes for text color
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println(GREEN + "Welcome to the Ultimate Mad Libs Experience!" + RESET);
System.out.println("Fill in the blanks to create a story that'll make you chuckle!\n");
// Prompting the user for inputs with fun and engaging text
System.out.print(CYAN + "Enter a whimsical name: " + RESET);
String name1 = scanner.nextLine();
System.out.print(BLUE + "Enter an amusing adjective: " + RESET);
String adjective1 = scanner.nextLine();
System.out.print(PURPLE + "Enter another amusing adjective: " + RESET);
String adjective2 = scanner.nextLine();
System.out.print(YELLOW + "Enter a curious noun: " + RESET);
String noun1 = scanner.nextLine();
System.out.print(RED + "Enter another curious noun: " + RESET);
String noun2 = scanner.nextLine();
System.out.print(GREEN + "Enter a lively verb: " + RESET);
String verb1 = scanner.nextLine();
System.out.print(CYAN + "Enter a quirky noun: " + RESET);
String noun3 = scanner.nextLine();
System.out.print(BLUE + "Enter a bizarre noun: " + RESET);
String noun4 = scanner.nextLine();
System.out.print(PURPLE + "Enter a hilarious adjective: " + RESET);
String adjective3 = scanner.nextLine();
System.out.print(YELLOW + "Enter another zany name: " + RESET);
String name2 = scanner.nextLine();
System.out.print(RED + "Enter a fantastical place: " + RESET);
String place1 = scanner.nextLine();
System.out.print(GREEN + "Enter an outlandish noun: " + RESET);
String noun5 = scanner.nextLine();
System.out.print(CYAN + "Enter an absurd number: " + RESET);
String number = scanner.nextLine();
System.out.print(BLUE + "Enter a peculiar noun: " + RESET);
String noun6 = scanner.nextLine();
System.out.println("\n" + YELLOW + "Hang tight, your zany story is on the way..." + RESET);
// Constructing the Mad Libs 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.";
// Output the completed story with colorful emphasis
System.out.println("\n" + GREEN + "Here's your wildly entertaining Mad Libs story:\n" + RESET + story);
scanner.close();
}
}
Instructions for Running the Program:
Save the Code: Save it to a file named Main.java.
Compile the Program:
Open a terminal or command prompt.
Navigate to the directory containing Main.java.
Compile the file using:
bash
javac Main.java
Run the Program:
Execute the compiled program with:
bash
java Main
Interact: Fill in the prompts with amusing and whimsical words to get a light-hearted and fun story output.
Features:
Colorful Output: Using ANSI color codes adds vibrancy to the console prompts and output, making the interaction more playful.
Engaging Prompts: Inviting users to think creatively and choose words that make the story amusing.
Maintained Template: The original story template remains unchanged, ensuring the integrity of your request.
Feel free to experiment with different combinations of words for various hilarious outcomes! Remember that the colors might not display correctly if your terminal doesn’t support ANSI escape codes, but most modern terminals do.
import java.util.Scanner;
public class Main {
// ANSI escape codes for text color
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println(GREEN + "Welcome to the Alan Becker Stick Figure Mad Libs!" + RESET);
System.out.println("Fill in the blanks to animate your story!\n");
// Prompting the user for inputs with Alan Becker and stick figure theme
System.out.print(CYAN + "Enter a name for your stick figure hero: " + RESET);
String name1 = scanner.nextLine();
System.out.print(BLUE + "Enter a daring adjective: " + RESET);
String adjective1 = scanner.nextLine();
System.out.print(PURPLE + "Enter another lively adjective: " + RESET);
String adjective2 = scanner.nextLine();
System.out.print(YELLOW + "Enter a noun related to digital animation: " + RESET);
String noun1 = scanner.nextLine();
System.out.print(RED + "Enter another tech-related noun: " + RESET);
String noun2 = scanner.nextLine();
System.out.print(GREEN + "Enter a verb that an artist might use: " + RESET);
String verb1 = scanner.nextLine();
System.out.print(CYAN + "Enter a noun representing a tool in a digital space: " + RESET);
String noun3 = scanner.nextLine();
System.out.print(BLUE + "Enter a bizarre noun related to a computer: " + RESET);
String noun4 = scanner.nextLine();
System.out.print(PURPLE + "Enter an adjective describing chaos: " + RESET);
String adjective3 = scanner.nextLine();
System.out.print(YELLOW + "Enter another stick figure's name: " + RESET);
String name2 = scanner.nextLine();
System.out.print(RED + "Enter a fantastical digital place: " + RESET);
String place1 = scanner.nextLine();
System.out.print(GREEN + "Enter an unexpected digital noun: " + RESET);
String noun5 = scanner.nextLine();
System.out.print(CYAN + "Enter a future year: " + RESET);
String number = scanner.nextLine();
System.out.print(BLUE + "Enter a noun symbolizing control in animation: " + RESET);
String noun6 = scanner.nextLine();
System.out.println("\n" + YELLOW + "Loading your stick figure adventure..." + RESET);
// Constructing the Mad Libs story
String story = "This morning " + name1 + " woke up feeling " + adjective1 +
". 'It is going to be an " + 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.";
// Output the completed story with colorful emphasis
System.out.println("\n" + GREEN + "Here's your Alan Becker stick figure Mad Libs story:\n" + RESET + story);
scanner.close();
}
}
Instructions:
Save the Program: Save this code to a file named Main.java.
Compile and Run: Use the terminal to compile and run:
bash
javac Main.java
java Main
Input Words: Follow the thematic prompts to input words related to the Alan Becker stick figure animations.
Enjoy the Story: Read the creative story you helped to create with an Alan Becker theme!
import java.util.Scanner;
public class Main {
// ANSI escape codes for text color
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println(GREEN + "Welcome to the Alan Becker Stick Figure Mad Libs!" + RESET);
System.out.println("Fill in the blanks to animate your story!\n");
// Prompting the user for inputs with Alan Becker and stick figure theme
System.out.print(CYAN + "Enter a name for your stick figure hero (e.g., Alan): " + RESET);
String name1 = scanner.nextLine();
System.out.print(BLUE + "Enter an adventurous adjective (e.g., daring): " + RESET);
String adjective1 = scanner.nextLine();
System.out.print(PURPLE + "Enter a lively adjective (e.g., animated): " + RESET);
String adjective2 = scanner.nextLine();
System.out.print(YELLOW + "Enter a noun related to digital animation (e.g., stick figure): " + RESET);
String noun1 = scanner.nextLine();
System.out.print(RED + "Enter another tech-related noun (e.g., cursor): " + RESET);
String noun2 = scanner.nextLine();
System.out.print(GREEN + "Enter a verb that an artist might use (e.g., draw): " + RESET);
String verb1 = scanner.nextLine();
System.out.print(CYAN + "Enter a noun representing a tool in a digital space (e.g., command prompt): " + RESET);
String noun3 = scanner.nextLine();
System.out.print(BLUE + "Enter a bizarre noun related to a computer (e.g., toolbar): " + RESET);
String noun4 = scanner.nextLine();
System.out.print(PURPLE + "Enter an adjective describing chaos (e.g., chaotic): " + RESET);
String adjective3 = scanner.nextLine();
System.out.print(YELLOW + "Enter another stick figure's name (e.g., The Chosen One): " + RESET);
String name2 = scanner.nextLine();
System.out.print(RED + "Enter a fantastical digital place (e.g., digital arena): " + RESET);
String place1 = scanner.nextLine();
System.out.print(GREEN + "Enter an unexpected digital noun (e.g., pixel): " + RESET);
String noun5 = scanner.nextLine();
System.out.print(CYAN + "Enter a future year (e.g., 2023): " + RESET);
String number = scanner.nextLine();
System.out.print(BLUE + "Enter a noun symbolizing control in animation (e.g., frame): " + RESET);
String noun6 = scanner.nextLine();
System.out.println("\n" + YELLOW + "Loading your stick figure adventure..." + RESET);
// Constructing the Mad Libs story
String story = "This morning " + name1 + " woke up feeling " + adjective1 +
". 'It is going to be an " + 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.";
// Output the completed story with colorful emphasis
System.out.println("\n" + GREEN + "Here's your Alan Becker stick figure Mad Libs story:\n" + RESET + story);
scanner.close();
}
}
Features and Instructions:
Examples Included: Each prompt now includes an example word in parentheses (e.g., "daring") to help guide the user on what type of word would fit well in the story.
Thematic Prompts: Still themed around Alan Becker's stick figure animations, maintaining a creative arc for storytelling.
Console Display: The story is output in color for those using terminals that support ANSI escape codes.
Running This Version:
Save the code as Main.java.
Compile with javac Main.java.
Run the program using java Main.
Follow the Prompts: Enter the requested inputs, using the examples as guidance for your imaginative choices.
Enjoy the Story: Create and read your personalized story that aligns with the Alan Becker stick figure theme.
import java.util.Scanner;
public class Main {
// ANSI escape codes for text color
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println(GREEN + "Welcome to the Alan Becker Stick Figure Mad Libs!" + RESET);
System.out.println("Fill in the blanks to bring your story to life!\n");
// Prompting the user for inputs with examples of how they'll appear in the story
System.out.print(CYAN + "Enter a name for your stick figure hero (e.g., Alan): \nExample: This morning [name] woke up...\n" + RESET);
String name1 = scanner.nextLine();
System.out.print(BLUE + "Enter an adventurous adjective (e.g., daring): \nExample: ...woke up feeling [adjective]...\n" + RESET);
String adjective1 = scanner.nextLine();
System.out.print(PURPLE + "Enter a lively adjective (e.g., animated): \nExample: 'It is going to be an [adjective] day!'\n" + RESET);
String adjective2 = scanner.nextLine();
System.out.print(YELLOW + "Enter a noun related to digital animation (e.g., stick figure): \nExample: a bunch of [noun]s were protesting...\n" + RESET);
String noun1 = scanner.nextLine();
System.out.print(RED + "Enter another tech-related noun (e.g., cursor): \nExample: ...to keep [noun] in stores...\n" + RESET);
String noun2 = scanner.nextLine();
System.out.print(GREEN + "Enter a verb that an artist might use (e.g., draw): \nExample: They began to [verb]...\n" + RESET);
String verb1 = scanner.nextLine();
System.out.print(CYAN + "Enter a noun representing a tool in a digital space (e.g., command prompt): \nExample: ...to the rhythm of the [noun]...\n" + RESET);
String noun3 = scanner.nextLine();
System.out.print(BLUE + "Enter a bizarre noun related to a computer (e.g., toolbar): \nExample: ...which made all the [noun]s very...\n" + RESET);
String noun4 = scanner.nextLine();
System.out.print(PURPLE + "Enter an adjective describing chaos (e.g., chaotic): \nExample: ...all the toolbars very [adjective]...\n" + RESET);
String adjective3 = scanner.nextLine();
System.out.print(YELLOW + "Enter another stick figure's name (e.g., The Chosen One): \nExample: Concerned, [name] texted...\n" + RESET);
String name2 = scanner.nextLine();
System.out.print(RED + "Enter a fantastical digital place (e.g., digital arena): \nExample: ...flew [name] to [place]...\n" + RESET);
String place1 = scanner.nextLine();
System.out.print(GREEN + "Enter an unexpected digital noun (e.g., pixel): \nExample: ...in a puddle of frozen [noun]...\n" + RESET);
String noun5 = scanner.nextLine();
System.out.print(CYAN + "Enter a future year (e.g., 2023): \nExample: [name] woke up in the year [number]...\n" + RESET);
String number = scanner.nextLine();
System.out.print(BLUE + "Enter a noun symbolizing control in animation (e.g., frame): \nExample: ...where [noun]s ruled the world.\n" + RESET);
String noun6 = scanner.nextLine();
System.out.println("\n" + YELLOW + "Crafting your stick figure epic..." + RESET);
// Constructing the Mad Libs story
String story = "This morning " + name1 + " woke up feeling " + adjective1 +
". 'It is going to be an " + 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.";
// Output the completed story with colorful emphasis
System.out.println("\n" + GREEN + "Here's your Alan Becker stick figure Mad Libs story:\n" + RESET + story);
scanner.close();
}
}
Features and Instructions:
Contextual Prompts: Each input request is followed by a short example of how that word will work in the story context. This helps users visualize the sentence structure.
Color-Coded Prompts: Prompts continue to use color for a visually engaging experience.
Console Implementation: Maintains a straightforward, text-based interaction for ease of use.
Instructions for Usage:
Save the program as Main.java.
Compile using javac Main.java.
Run with java Main.
Follow Prompts: Input the requested types of words while considering how they'll fit into the story using the given examples.
Read the Story: Enjoy the thematic Alan Becker stick figure narrative you helped create!