Question

Question 1:    * - Print out the welcome message: "Welcome to this choose your own...

Question 1:

   * - Print out the welcome message: "Welcome to this choose your own adventure system!"

   * - Begin the play again loop:

   * - Prompt for a filename using the promptString method with the prompt:

   * "Please enter the story filename: "

   * - Prompt for a char using the promptChar method with the prompt:

   * "Do you want to try again? "

   * - Repeat until the character returned by promptChar is an 'n'

   * - Print out "Thank you for playing!", terminated by a newline.

public static void main(String[] args) {

  

}

}

Question 2:

Prints out a line of characters to System.out. The line should be terminated by a new line.

   *

   * @param len The number of times to print out c.

   * @param c The character to print out.

public static void printLine(int len, char c) {

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1)

import java.util.*;
import java.io.*;

public class Main {

    static Scanner sc= new Scanner(System.in);

    // promptString method
    public static void promptString()
    {


        System.out.println("Please enter the story filename");
    }


    // promptchar method
    public static char  promptchar ()throws Exception
    {
        System.out.println("Do you want to try again? ");
        char ch = (char) System.in.read();
        return ch;

    }
    public static void main (String args[])  throws Exception{

        System.out.println("Welcome to this choose your own adventure system!");



        char ch='y';

        while(ch!='n')
        {

              // method call to promptString to print string
            promptString();
         // read char
          ch =promptchar();




        }
        // print thank you message
        System.out.println("Thank you for playing!");
    }

}

Sample Run:

sample [CUsersdarshiDesktopyHomeworkLibsample] - srcMain.java [sample] Intelliu IDEA Eie Edit צ¡ew Navigate gode Analyze Befactor

Question 2:

import java.util.*;
import java.io.*;

public class Main {

    static Scanner sc= new Scanner(System.in);


    //printLine(int n,char c) method
    public static void printLine(int n,char c)
    {
        // to print char c n times
        int i=0;
        for(i=0;i<n;i++)
            System.out.print(c);

        System.out.print("\n"); // to print newline



    }
       public static void main (String args[])  throws Exception{


      char ch='z';
      int n=14;
      printLine(n,ch);   // method to print char for n times



    }

}

Sample Run

sample [CUsersdarshiDesktopyHomeworkLibsample] - srcMain.java [sample] Intelliu IDEA Eie Edit Yew Navigate gode Analyze Befactor B

Add a comment
Know the answer?
Add Answer to:
Question 1:    * - Print out the welcome message: "Welcome to this choose your own...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How can i print a diamond implementing these methods public static void printNChars(int n, char c))....

    How can i print a diamond implementing these methods public static void printNChars(int n, char c)). This method will print n times the character c in a row, public static void printDiamond(int size, char edgeChar, char fillChar). This method will call printNChars() method to print the shape. It will use the edgeChar to print the sides and the fillChar to fill the interior of the shape. The shape will have a height and a width of the given size. public...

  • Please help me. package a1; public class Methods {    /*    * Instructions for students:...

    Please help me. package a1; public class Methods {    /*    * Instructions for students: Use the main method only to make calls to the    * other methods and to print some testing results. The correct operation of    * your methods should not depend in any way on the code in main.    *    * Do not do any printing within the method bodies, except the main method.    *    * Leave your testing code...

  • Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray();...

    Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray(); char[] reverse = new char[original.length]; for(int i =0; i<s.length(); i++){ reverse[i] = original[original.length-1-i]; } return new String(reverse); } /**  * Takes in a string containing a first, middle and last name in that order.  * For example Amith Mamidi Reddy to A. M. Reddy.  * If there are not three words in the string then the method will return null  * @param name in...

  • Java class quiz need help~ This is the Backwards.java code. public class Backwards { /** *...

    Java class quiz need help~ This is the Backwards.java code. public class Backwards { /** * Program starts with this method. * * @param args A String to be printed backwards */ public static void main(String[] args) { if (args.length == 0) { System.out.println("ERROR: Enter a String on commandline."); } else { String word = args[0]; String backwards = iterativeBack(word); // A (return address) System.out.println("Iterative solution: " + backwards); backwards = recursiveBack(word); // B (return address) System.out.println("\n\nRecursive solution: " +...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of...

    import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of this class in the * MasterMind program. * * @author TODO add your name here */ public class MasterMind { /** * Prompts the user for a value by displaying prompt. * Note: This method should not add a new line to the output of prompt. * * After prompting the user, the method will consume an entire * line of input while reading...

  • I need assistance with this method. Don't change the method type, decoding UTF8 import java.util.Scanner; /**...

    I need assistance with this method. Don't change the method type, decoding UTF8 import java.util.Scanner; /** * Determines if a sequence of cells of length len in a game board is clear or not. This is used * to determine if a ship will fit on a given game board. The x and y coordinates passed in as * parameters represent the top-left cell of the ship when considering the grid. * * @param board The game board to search....

  • You will need to think about problem solving. There are several multi-step activities. Design, compile and...

    You will need to think about problem solving. There are several multi-step activities. Design, compile and run a single Java program, StringEx.java, to accomplish all of the following tasks. Add one part at a time and test before trying the next one. The program can just include a main method, or it is neater to split things into separate methods (all static void, with names like showLength, sentenceType, lastFirst1, lastFirst), and have main call all the ones you have written...

  • Java Homework Problems: 4. • Examine AddImport.java. – Perform the following: – Replace the fully qualified...

    Java Homework Problems: 4. • Examine AddImport.java. – Perform the following: – Replace the fully qualified name to access the Jlabel component with an import statement. – To import classes from the util package, replace multiple import statements with a single import statement. /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Calendar; import java.util.Date; public...

  • You will create your own silly story based on information provided by the user. For example,...

    You will create your own silly story 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: Congratulations! Today is your 345 day. You're off to Colorado! You're off and away! You have brains in your stomach, You...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT