Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your Second Program (with Scanner Input) This program is quite similar to the fi

ID: 3910148 • Letter: Y

Question

Your Second Program (with Scanner Input)

This program is quite similar to the first, so you might consider making a copy of your first program as a starting point for your second (but be sure to submit two distinct java programs and thus two distinct java files). In future weeks, we’ll discuss better techniques for code reuse than simply copying and pasting, but for this assignment, this is a fine way to shorten the work you have to do. The goal of the second program is to ask the user for the unique lines of the story and then output the “Star Wars Story” with the lines the user submitted. A sample execution might look like:

(Program prompt) “Please enter the Title of the Story:”

(User Input) “Episode 8 : A New Knight”

(Program prompt) “Please enter the content of the Story:”

(User Input) “Princess Leia discovers she is strong with the Force.”

(Program prompt) “Please enter the Remainder of the Story:”

(User Input) “Will Leia lead the Jedi Knights to justice?”

(Program output)

“Episode 8 : A New Knight”

“A long time ago,”

“In a galaxy far, far away…”

“Princess Leia discovers she is strong with the Force.”

“There was much strife and unrest.”

“Will Leia lead the Jedi Knights to justice?”

“”

This program will be inspected for the same characteristics as the first program, so be sure your code compiles, is simple, and has no duplicate print statements.

Name Instructions

You must name the files “TellingStories.java” and “TellingDynamicStories.java”

You must name your methods (for both files) as follows:public static void main(String[] args) //every program will have one of these

main will either call “TellStoryOne()” and “TellStoryTwo()” in the first file, or call “tellDynamicStory(…)” in the second file, but the main method will be quite short.

public static intro()

public static middle()

public static outro()

public static tellStoryOne() //should call intro(), middle() and outro()

public static tellStoryTwo() //same as above

public static tellDynamicStory(String title, String content, String remainder)

This function will be provided the input from main, which will use a Scanner to ask the user for each of the strings, as demonstrated in the output above

edit: you do not need the first program. i just need the code to output the lines above

Explanation / Answer

Here is your code to take inputs form user and display like sample output.

import java.util.Scanner;

public class Main

{

    public static void tellDynamicStory(String title, String content, String remainder)

    {

        // Prints the title, content and remainder in an order.

        System.out.println(" " + title);

        System.out.println(" A long time ago,");

        System.out.println(" In a galaxy far, far away...");

        System.out.println(content);

        System.out.println("There was much strife and unrest.");

        System.out.println(" " + remainder);

    }

   

                public static void main(String[] args) {

                    Scanner sc = new Scanner(System.in);

                    // Takes the input from user one by one

                                System.out.println("Please enter the Title of the Story:");

                                String title = sc.nextLine();

                                System.out.println("Please enter the content of the Story:");

                                String content = sc.nextLine();

                                System.out.println("Please enter the Remainder of the Story:");

                                String remainder = sc.nextLine();

                                // Calls the tellDynamicStory and passes the user inputs

                                tellDynamicStory(title, content, remainder);

                }

}

OUTPUT

Please enter the Title of the Story:                                                                                             
Episode 8: A New Knight                                                                                                          
Please enter the content of the Story:                                                                                           
Princess Leia discovers she is strong with the Force                                                                             
Please enter the Remainder of the Story:                                                                                         
Will Leia lead the Jedi Knights to justice                                                                                       
        Episode 8: A New Knight                                                                                                  
        A long time ago,                                                                                                         
        In a galaxy far, far away...                                                                                             
Princess Leia discovers she is strong with the Force                                                                             
There was much strife and unrest.                                                                                                
        Will Leia lead the Jedi Knights to justice

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote