Question

JAVA QUESTION: JAVA QUESTION instructions: make something similar to the example output that is given below...

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 .

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

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("\n Original Data \n");

// 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("\n 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("\n Please type a adjective: ");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

System.out.print("\n 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("\n Please type a funny-noise: ");

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

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

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

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

System.out.print("\n 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("\n Please type a adjective: ");

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

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

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

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

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

System.out.print("\n 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("\n Replaced Data \n");

// 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 .

Add a comment
Know the answer?
Add Answer to:
JAVA QUESTION: JAVA QUESTION instructions: make something similar to the example output that is given below...
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
  • Write a program that plays a game where a player is asked to fill in various...

    Write a program that plays a game where a player is asked to fill in various words of a mostly complete story without being able to see the rest. Then the user is shown his/her story, which is often funny. The input for your program is a set of story files, each of which contains “placeholder” tokens surrounded by < and >, such as: One of the most <adjective> characters in fiction is named "Tarzan of the <plural-noun> ." Tarzan...

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