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

JAVA QUESTION: JAVA QUESTION instructions: make something similar to the example

ID: 3715315 • Letter: J

Question

JAVA QUESTION:

JAVA QUESTION

instructions: make something similar to the example output that is given below + JAVA DOC

Madlibs Lab:

Here are the input files examples

Tarzan txt :

One of the most <adjective> characters in fiction is named
"Tarzan of the <plural-noun> ." Tarzan was raised by a/an
<noun> and lives in the <adjective> jungle in the
heart of darkest <place> . He spends most of his time
eating <plural-noun> and swinging from tree to <noun> .
Whenever he gets angry, he beats on his chest and says,
" <funny-noise> !" This is his war cry. Tarzan always dresses in
<adjective> shorts made from the skin of a/an <noun>
and his best friend is a/an <adjective> chimpanzee named
Cheetah. He is supposed to be able to speak to elephants and
<plural-noun> . In the movies, Tarzan is played by <person's-name> .

Sample Output to screen

Please type a adjective:happy

Please type a plural-noun:roosters

Please type a noun:dog

Please type a adjective:green

Please type a place:Texas

Please type a plural-noun:cookies

Please type a noun:senator

Please type a funny-noise:burp

Please type a adjective:silly

Please type a noun:raisen

Please type a adjective:old

Please type a plural-noun:cats

Please type a person's-name:Tom

Sample Outputfile

One of the most happy characters in fiction is named "Tarzan of the roosters ." Tarzan was raised by a/an dog and lives in the green jungle in the heart of darkest Texas . He spends most of his time eating cookies and swinging from tree to senator . Whenever he gets angry, he beats on his chest and says, " burp !" This is his war cry. Tarzan always dresses in silly shorts made from the skin of a/an raisen and his best friend is a/an old chimpanzee named Cheetah. He is supposed to be able to speak to elephants and cats . In the movies, Tarzan is played by Tom .

Explanation / Answer

package string;

import java.io.*;

import java.util.*;

// Class FindReplace definition

public class FindReplace

{

// To store the string read from file

String original[];

// To store number of lines

int rows = 0;

// Method to read file contents and stores it in string array

void fileRead()

{

// To handle file not found

try

{

// Scanner class object created to read file

Scanner readF = new Scanner(new File("FindReplaceData.txt"));

// Loops till end of the file to count number of lines

while(readF.hasNextLine())

{

// Read one line at a time from file

readF.nextLine();

// Increase the row counter

rows++;

}// End of while loop

// Allocates number of rows  

original = new String[rows];

// Close the file

readF.close();

// Re opens the file for reading data

readF = new Scanner(new File("FindReplaceData.txt"));

// Reset the row counter to zero

rows = 0;

// Loops till end of the file to read data

while(readF.hasNextLine())

{

// Read one line at a time from file and stores at rows index position of original array

original[rows] = readF.nextLine();

// Increase the row counter by one

rows++;

}// End of while loop

System.out.print(" Original Data ");

// loops till number of rows and displays the original data

for(int y = 0; y < rows; y++)

System.out.println(original[y]);

// Close the file

readF.close();

}// End of try block

// Catch block to handle FileNotFoundException

catch(FileNotFoundException fe)

{

System.out.println(" File not found");

}// End of catch block

}// End of method

// Method to find and replace

void findReplace()

{

// Scanner class object created to accept data from console

Scanner sc = new Scanner(System.in);

// Creates find array

String find[] = {"<adjective>", "<plural-noun>", "<noun>", "<adjective>", "<place>", "<plural-noun>", "<noun>", "<funny-noise> !",

"<adjective>", "<noun>", "<adjective>", "<plural-noun>", "<person's-name>"};

// Creates an array to store replace with string entered by the user

String replaceWith[] = new String[find.length];

// Accepts the string to replace from the user and replaces it

System.out.print(" Please type a adjective: ");

replaceWith[0] = " " + sc.next() + " ";

original[0] = original[0].replaceAll(find[0], replaceWith[0]);

System.out.print(" Please type a plural-noun: ");

replaceWith[1] = " " + sc.next() + " ";

original[1] = original[1].replaceAll(find[1], replaceWith[1]);

System.out.print(" Please type a noun: ");

replaceWith[2] = " " + sc.next() + " ";

original[2] = original[2].replaceAll(find[2], replaceWith[2]);

System.out.print(" Please type a adjective: ");

replaceWith[3] = " " + sc.next() + " ";

original[2] = original[2].replaceAll(find[3], replaceWith[3]);

System.out.print(" Please type a place: ");

replaceWith[4] = " " + sc.next() + " ";

original[3] = original[3].replaceAll(find[4], replaceWith[4]);

System.out.print(" Please type a plural-noun: ");

replaceWith[5] = " " + sc.next() + " ";

System.out.print(" Please type a noun: ");

replaceWith[6] = " " + sc.next() + " ";

original[4] = original[4].replaceAll(find[5], replaceWith[5]);

original[4] = original[4].replaceAll(find[6], replaceWith[6]);

System.out.print(" Please type a funny-noise: ");

replaceWith[7] = " " + sc.next() + " ";

original[6] = original[6].replaceAll(find[7], replaceWith[7]);

System.out.print(" Please type a adjective: ");

replaceWith[8] = " " + sc.next() + " ";

System.out.print(" Please type a noun: ");

replaceWith[9] = " " + sc.next() + " ";

original[7] = original[7].replaceAll(find[8], replaceWith[8]);

original[7] = original[7].replaceAll(find[9], replaceWith[9]);

System.out.print(" Please type a adjective: ");

replaceWith[10] = " " + sc.next() + " ";

original[8] = original[8].replaceAll(find[10], replaceWith[10]);

System.out.print(" Please type a plural-noun: ");

replaceWith[11] = " " + sc.next() + " ";

original[10] = original[10].replaceAll(find[11], replaceWith[11]);

System.out.print(" Please type a person's-name: ");

replaceWith[12] = " " + sc.next() + " ";

original[10] = original[10].replaceAll(find[12], replaceWith[12]);

// Close the scanner

sc.close();

}// End of method

// Method to display replaced data

void display()

{

System.out.print(" Replaced Data ");

// loops till number of rows and displays the replaced data

for(int y = 0; y < rows; y++)

System.out.println(original[y]);

}// End of while loop

// main method definition

public static void main(String args[])

{

// Creates an object of class FindReplace

FindReplace fr = new FindReplace();

// Call the method to read file contents

fr.fileRead();

// Calls the method to find and replace

fr.findReplace();

// Calls the method to display replaced data

fr.display();

}// End of main method

}// End of class

Sample Output:


Original Data
One of the most <adjective> characters in fiction is named
"Tarzan of the <plural-noun> ." Tarzan was raised by a/an
<noun> and lives in the <adjective> jungle in the
heart of darkest <place> . He spends most of his time
eating <plural-noun> and swinging from tree to <noun> .
Whenever he gets angry, he beats on his chest and says,
" <funny-noise> !" This is his war cry. Tarzan always dresses in
<adjective> shorts made from the skin of a/an <noun>
and his best friend is a/an <adjective> chimpanzee named
Cheetah. He is supposed to be able to speak to elephants and
<plural-noun> . In the movies, Tarzan is played by <person's-name> .

Please type a adjective: happy

Please type a plural-noun: roosters

Please type a noun: dog

Please type a adjective: green

Please type a place: Texas

Please type a plural-noun: cookies

Please type a noun: senator

Please type a funny-noise: burp

Please type a adjective: sily

Please type a noun: raisen

Please type a adjective: old

Please type a plural-noun: cats

Please type a person's-name: Tom

Replaced Data
One of the most happy characters in fiction is named
"Tarzan of the roosters ." Tarzan was raised by a/an
dog and lives in the green jungle in the
heart of darkest Texas . He spends most of his time
eating cookies and swinging from tree to senator .
Whenever he gets angry, he beats on his chest and says,
" burp " This is his war cry. Tarzan always dresses in
sily shorts made from the skin of a/an raisen
and his best friend is a/an old chimpanzee named
Cheetah. He is supposed to be able to speak to elephants and
cats . In the movies, Tarzan is played by Tom .