JAVA!! Create your own silly story (not this one) based on information provided
ID: 3869895 • Letter: J
Question
JAVA!! Create your own silly story (not this one) based on information provided by the user. For example, the parts in bold were entered by the user. For ideas see: Mad Libs
My Silly Story
name: Frank Zhang
whole number: 345
body part: stomach
noun: cup
floating point number: 1.23
clothing article: hat
destination: Colorado
goal: degree
The resulting story is:
Requirements: The main method should contain all input code (e.g., Scanner instance) and have at least 5 user prompts inputting values with nextInt(), nextDouble(), next() and nextLine(). All output code (e.g., print statements) must be in the main method as well.
The prepareStory method takes the arguments passed in and prepares the entire story, using at least 5 parameters, as one long String that is returned. The author's name (e.g., the same name that is in the file header comment) must be included in the String that is returned. Don't pass the author's name as a parameter, but include as a string literal within the prepareStory method.
import java.util.Scanner;
public class MySillyStory {
//add prepareStory method
public static void main(String[] args) {
//prompt the user
//pass the responses to the prepareStory method
//print out the story returned from prepareStory
}
}
Explanation / Answer
MySillyStory.java
import java.util.Scanner;
public class MySillyStory {
// add prepareStory method
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("My Silly Story");
// prompt the user
System.out.print("name: ");
String name = scan.nextLine();
System.out.print("whole number: ");
int num = scan.nextInt();
System.out.print("body part: ");
String bodyPart = scan.next();
System.out.print("noun: ");
String noun = scan.next();
System.out.print("floating point number:");
float f = scan.nextFloat();
System.out.print("clothing article: ");
String art = scan.next();
System.out.print("destination: ");
String destination = scan.next();
System.out.print("goal: ");
String goal = scan.next();
// pass the responses to the prepareStory method
String story = prepareStory(num, destination, bodyPart, art, noun, f,
name, goal);
// print out the story returned from prepareStory
System.out.println("-------------------------------------");
System.out.println(story);
}
public static String prepareStory(int number, String destination,
String bodyPart, String clothing, String noun, double floatNum,
String name, String goal) {
String story = "Congratulations! Today is your "
+ number
+ " day. You're off to "
+ destination
+ "! You're off and away! You have brains in your "
+ bodyPart
+ ", You have feet in your "
+ clothing
+ ". You can steer yourself any direction you choose. You're on your own with $"
+ floatNum
+ ". And you know what you know. And YOU are the "
+ noun
+ " who'll decide where to go. be your name "
+ name
+ " or Bixby or Bray or Mordecai Ali Van Allen O'Shea, You're off to "
+ destination
+ "! Today is your day! Your "+goal+" is waiting. So...get on your way! Based on Dr. Seuss ";
return story; // replace with your code
}
}
Output:
My Silly Story
name: Frank Zhang
whole number: 345
body part: stomach
noun: cup
floating point number:1.23
clothing article: hat
destination: Colorado
goal: degree
-------------------------------------
Congratulations!
Today is your 345 day.
You're off to Colorado!
You're off and away!
You have brains in your stomach, You have feet in your hat.
You can steer yourself any direction you choose.
You're on your own with $1.2300000190734863. And you know what you know.
And YOU are the cup who'll decide where to go.
be your name Frank Zhang or Bixby or Bray
or Mordecai Ali Van Allen O'Shea,
You're off to Colorado!
Today is your day!
Your degree is waiting. So...get on your way!
Based on Dr. Seuss
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.