Question

In: Computer Science

Write a Java program which is a story with blanks that will be filled in by...

Write a Java program which is a story with blanks that will be filled in by the user’s input. Ask the user bunch of questions and then make up a story with all of the user’s answers.

Requirement

  • Use a Scanner object to interact with the user.
  • The values the user enters need to be stored in appropriate type variables. A program without using variables will get zero points.
  • The questions that you ask must satisfy the following conditions
  • You must prompt minimum for 8 responses
  • At least one question must ask for an integer response. It must be read using the nextInt() method.
  • At least one question must ask for a floating point value. It must be read using either the nextFloat() or the nextDouble() method.
  • At least one question must be asked for a String response. It must be read using next() or nextLine() method.
  • At least one method from the Math class must be used in your story (I used sqrt)
  • At lease one method must be used from the String class. (I used substring and indexOf, lastIndeOf methods

Methods

Main method

  • This method creates a Scanner object,
  • Asks the user how many times they want to use the app
  • Create a for loops, in the for loop call the method story

Story:

  • This method gets the Scanner object as its parameter
  • Ask the user the questions you designed
  • After getting the user’s responses, print a short story where you use the user’s input to fill in blanks in the story. You must come up with your own story and not using the provided one.
  • Display the story

Sample output

/* The highlighted words in the story are the content of the variables*/

How many stories are you making: 2

Answer a few questions and I will make up a story for you

What is your name? Sam

What are three of your favorite Halloween characters?

Charcter 1 --> Ghost

Charcter 2--> Skeleton

Character 3--> Jack-O-Lantern

What is the spookiest place you can think of? graveyard

What is the address of the graveyard? 13000 Ghost Town

What is your favorite kind of candy? Kit Kat

How would you describe something that is very scary? dark

What is favorite number? 25

What is your favorite website? Facebook

Once upon a dark night, Sam went for a jog to the place at 13000 Ghost Town.

When Sam got there Sam screamed when Sam saw a very scary Ghost.

The Ghost was very friendly after Sam gave it a Kit Kat.

Then the Ghost introduced Sam to his friends the Skeleton and Jack-O-Lantern.

The Ghost said he had more friends if Sam wanted to meet them.

Sam gave the Ghost $5.0 to NOT bring out his other friends and then Sam ran away.

Sam went online to Facebook to message his friends about the whole thing. Bye, have a good day.

Answer a few questions and I will make up a story for you

What is your name? Jost

What are three of your favorite Halloween characters?

Charcter 1 --> Vampire

Charcter 2--> Jack-O-Lantern

Character 3--> Creepy clown

What is the spookiest place you can think of? dark jungle

What is the address of the dark jungle? 123 creepy st

What is your favorite kind of candy? sour candy

How would you describe something that is very scary? frightening

What is favorite number? 36

What is your favorite website? Discord

Once upon a frightening night, Jost went for a jog to the place at 123 creepy st.

When Jost got there Jost screamed when Jost saw a very scary Vampire.

The Vampire was very friendly after Jost gave it a sour candy.

Then the Vampire introduced Jost to his friends the Jack-O-Lantern and Creepy clown.

The Vampire said he had more friends if Jost wanted to meet them.

Jost gave the Vampire $6.0 to NOT bring out his other friends and then Jost ran away.

Jost went online to Discord to message his friends about the whole thing. Bye, Have a good day

Solutions

Expert Solution

package practice;

import java.util.Scanner;

public class first {
        public static void main(String[] args) {
                System.out.println("How many Stories are you making?");
        //intializing scanner class object
            Scanner sc = new Scanner(System.in);
        //total number of stories user wants to create
                int numOfStories = sc.nextInt();
                for(int i = 0; i<numOfStories; i++){
            //calling story function and passing scanner object as parameter
                    story(sc);
                }
        }
    // static function 
        public static void story(Scanner sc){
            
            System.out.println("Answer a few Question and we will frame a story for you...");
            System.out.println("What is your name");
            sc.nextLine();
            String userName = sc.nextLine(); 
            System.out.println("What is your gender (M/F)?");
            String gender = sc.nextLine();
            System.out.println("What is the pin code of your area?");
            int pinCode = sc.nextInt();
            sc.nextLine();
            System.out.println("What is the name of your native village?");
            String villageName = sc.nextLine();
            System.out.println("Which is your fathers name ?");
            String farthersName = sc.nextLine();
            System.out.println("What is your height in feet?");
            double height = sc.nextDouble();
            System.out.println("Which social media website you use the most ?");
            sc.nextLine();
            String socialMedia = sc.nextLine();
            System.out.println("Choose any number between 1-100 ?");
            int money = sc.nextInt();
            sc.nextLine();
            System.out.println("Which is your favourite colour ?");
            String fvrtColor = sc.nextLine();
            sc.nextLine();
        // string class function used are .equals and .concat
        // math class power(x,y) is used
            if(gender.equals("M")){
                System.out.println("A boy named " + userName +" is found missing since last thrusday. As per the data given by this father Mr. "+ farthersName + ". He has left his house last thrusday at 9:00 AM ");
                System.out.println("from his native village "+villageName + ". His height is " + height + " and he is wearnig white color t-shirt and "+fvrtColor + " jeans and is Addicted to " + socialMedia + ".");
                System.out.println("Whosever found this guy can report to his father at " + villageName.concat(" " + pinCode) + " and he will be awarded with " + Math.pow(money, 2) + " rupess and a dairy milk choclate");
                System.out.println("Please help us in finding this charming and intelligent guy.");
            }
            else{
                System.out.println("A girl named " + userName + " is found missing since last thrusday. As per the data given by this father Mr. "+ farthersName + ". she has left his house last thrusday at 9:00 AM from his native village i.e "+villageName);
                System.out.println("from his native village "+villageName + ". His height is " + height + " and she is wearnig white color top and "+fvrtColor + " jeans and is Addicted to " + socialMedia + ".");
                System.out.println("Whosever found this guy can report to her father at " + villageName.concat(" " + pinCode) + " and he will be awarded with " + Math.pow(money, 2) + " rupess and a dairy milk choclate");
                System.out.println("Please help us in finding this charming and intelligent girl.");
            }
            
        }
}

press enter after entering all details to create the sotry.

you can customise the story if you find something intresting. Comment in case you have any doubt.


Related Solutions

JAVA CODE FILL IN THE BLANKS you are to complete the skeleton program by completing *...
JAVA CODE FILL IN THE BLANKS you are to complete the skeleton program by completing * the To Do sections. I would suggest doing this a * little bit at a time and testing each step before you * go on to the next step. * *           Add whatever code is necessary to complete this assignment *********************************************************************/ //Add whatever code is necessary to complete this assignment public class Methods {    public static void main(String[] args)    {...
Write Java program Lab52.java which reads in a line of text from the user. The text...
Write Java program Lab52.java which reads in a line of text from the user. The text should be passed into the method: public static String[] divideText(String input) The "divideText" method returns an array of 2 Strings, one with the even number characters in the original string and one with the odd number characters from the original string. The program should then print out the returned strings.
Write a Java program to create an array of a specific size (which is an input...
Write a Java program to create an array of a specific size (which is an input from the user) and fill it with random numbers between 1 and 100. Then sort the array and count how many of these numbers are originally at sorted position. Display that original array, the sorted array, and the count (number of elements originally at sorted position).
Write a program in Java which will search a space delimited string of integers for the...
Write a program in Java which will search a space delimited string of integers for the two values which add up to a provided amount. The program must output th following text to the command prompt/console: Indexes: { Index of first number} { Index of second number} Example One: NumSerach( 100, " 5 75 25"); output: Indexes: 1 2
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
********JAVA************ This program deals with graphs and path-finding within them. write a program which allows the...
********JAVA************ This program deals with graphs and path-finding within them. write a program which allows the user to enter multiple levels of a text, consisting of a 'start', an 'exit', 'walls', and 'floors'. The letter S represents the start. E is the exit. O (the letter 'oh') represents a 'floor' (meaning a path you can follow). X is a wall (meaning a block you cannot pass). The program will accept Standard Input (System.in), It is up to you whether you...
java program: Please save the program with the name ‘Palindrome.java’ Write a method which return true...
java program: Please save the program with the name ‘Palindrome.java’ Write a method which return true if the string parameter is a palindrome. This is the output example: Lets check if a string is a palindrom Please give me a string: abc No, its not a Palindrom Lets check if a string is a palindrom Please give me a string: noon Yes, its a Palindrom
Write a program in java processing. Write a program that does the following: · Assume the...
Write a program in java processing. Write a program that does the following: · Assume the canvas size of 500X500. · The program asks the user to enter a 3 digit number. · The program then checks the value of the first and last digit of the number. · If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer. · If the two digits are odd, it...
How to write IO program in java?
How to write IO program in java?
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in English (dictionary), to find the number of misspelled words in a story file called Alcott-little-261.txt. Please note that the dictionary words are all lower-cased and there are no punctuation symbols or numbers. Hence it is important that you eliminate anything other than a-z and A-Z and then lower case story words for valid comparisons against the WordList file. When you read each line of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT