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) {
}
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](http://img.homeworklib.com/questions/2e49a8f0-f6ea-11eb-8e54-1b83ec6f3964.png?x-oss-process=image/resize,w_560)
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](http://img.homeworklib.com/questions/2ec81d50-f6ea-11eb-bd26-f59490dcef76.png?x-oss-process=image/resize,w_560)
Question 1: * - Print out the welcome message: "Welcome to this choose your own...
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...
IN JAVA Overview 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 the user to decide between different forms...
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...
Exercise 1 • Examine ShoppingCart.java. – Perform the following: – Use the indexOf method to get the index for the space character (" ") within custName. Assign it to spaceIdx. – Use the substring method and spaceIdx to get the first name portion of custName. Assign it to firstName and print firstName. public class ShoppingCart { public static void main (String[] args){ String custName = "Steve Smith"; String firstName; int spaceIdx; // Get the...
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 { /** * 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 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...
what are the debuggers in Java? import java.text.NumberFormat; /** * * This class represents a circle that would be used as part * of a larger geometry application */ public class Circle { private double radius; private NumberFormat numberFormat; /** * Constructor for the Circle. * @param radius for the circle */ public Circle(double r) { radius = r; } /** * This method uses the radius of the circle to compute...
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....
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...