Answered Essay: You will create the ShoutBox class for your Virtual World. Your ShoutBox class will have two methods: Method s

You will create the ShoutBox class for your Virtual World. Your ShoutBox class will have two methods: Method shoutOutCannedMessage() will return type String. The shoutOutCannedMessage will use an Array or an ArrayList to store 10 messages of type String. For those of you who are more advanced with your Java skills, you could use a HashMap for the data structure. You can load this data structure with 10 messages of your choosing. You can initialize your Array or ArrayList with the messages or have the user enter the messages. The choice is yours. shoutOutCannedMessage() will loop through the data structure to first display all canned messages and allow the user to select one. The shoutOutCannedMessage() will return the selected message String. The shoutOutRandomMessage() method will return type String. The shoutOutRandomMessage() will use several Arrays or an ArrayList to store words. You will have one data structure that holds a list of words that are subjects, another data structure that holds a list of words that are objects, another that holds a list of verbs, another that holds a list of adverbs, and another that holds a list of adjectives. You can initialize your data structures with words or have the user enter the words. The choice is yours. The shoutOutRandomMessage() method will use a random number generator that selects one word from each data structure to form a random message. The shoutOutRandomMessage() method will return the random message as a String data type. Random messages will be of the form: Subject – Verb – Adjective – Object – Adverb. Document your shoutOutRandomMessage() method to explain the code.

Expert Answer

 

/*The source code of the above said program is given below:*/

import java.util.List;

import java.util.Random;

import java.util.Scanner;

import java.util.ArrayList;

public class ShoutBox {

public static String shoutOutCannedMessage()

{

/*declaring arraylist of type String*/

List<String> myArray = new ArrayList<String>();

/*storing 10 messages into arraylist*/

myArray.add(“Whatever you are, be a good one!”);

myArray.add(“May you live every day of your life!”);

myArray.add(“Try Again and Again!”);

myArray.add(“We become what we think about!”);

myArray.add(“Never give up!”);

myArray.add(“Success is the best revenge!”);

myArray.add(“Always dream big!”);

myArray.add(“Nothing is impossible!”);

myArray.add(“Always keep hope!”);

myArray.add(“All that glitters is not gold!”);

/*displaying all canned messages*/

System.out.println(“The canned messages are: “);

for (int i = 0; i < myArray.size(); i++)

{

String str = myArray.get(i);

System.out.println(i+1 + “. : ” + str);

}

/*taking the message number as input from user */

System.out.println(“nSelect the index number of message that you want to be returned: “);

Scanner in = new Scanner(System.in);

int num = in.nextInt();

in.close();

/*returning the message accordingly*/

if(num<=10 && num>=1)

{

return myArray.get(num-1);

}

else

{

System.out.println(“Message index number is invalid!!”);

return null;

}

}

public static String shoutOutRandomMessage()

{

/*declaring and initializing arrays of subjects, objects,verbs,adjectives and adverbs;

* all of them are array of Strings*/

String[] subjects = new String[]{“Alice”,”Bob”,”Tom”,”They”,”We”,”You”,”He”,”She”};

String[] objects = new String[]{“tea”,”coffee”,”answers”,”books”,”milk”,”story-books”,”puzzels”,”milk-shakes”};

String[] verbs = new String[]{“drinks”,”drink”,”knows”,”love”,”loves”,”know”,”reads”,”read”};

String[] adjectives = new String[]{“hot”,”cold”,”correct”,”incorrect”,”good”,”bad”,”interesting”,”boaring”};

String[] adverbs = new String[]{“daily”,”everyday”,”already”,”always”,”quickly”,”now”,”today”,”completely”};

/*generating different random number for each array */

/*minimum range for random number for all the arrays is same i.e.0*/

int min=0;

/*generating random number for subjects array*/

int max=subjects.length-1;

Random rn = new Random();

int range = max – min + 1;

int randomNum = rn.nextInt(range) + min;

/*choosing the random element from subjects array and putting it in string result1*/

String result1 = subjects[randomNum];

/*generating random number for verbs array*/

max=verbs.length-1;

rn = new Random();

range = max – min + 1;

randomNum = rn.nextInt(range) + min;

/*choosing the random element from verbs array and concating it with string result1 and storing in String result2*/

String result2 = result1 + ” “+verbs[randomNum];

/*generating random number for adjectives array*/

max=adjectives.length-1;

rn = new Random();

range = max – min + 1;

randomNum = rn.nextInt(range) + min;

/*choosing the random element from adjectives array and concating it with string result2 and storing in String result3*/

String result3 = result2+ ” “+ adjectives[randomNum];

/*generating random number for objects array*/

max=objects.length-1;

rn = new Random();

range = max – min + 1;

randomNum = rn.nextInt(range) + min;

/*choosing the random element from objects array and concating it with string result3 and storing in String result4*/

String result4 = result3+ ” ” +objects[randomNum];

/*generating random number for adverbs array*/

max=adverbs.length-1;

rn = new Random();

range = max – min + 1;

randomNum = rn.nextInt(range) + min;

/*choosing the random element from adverbs array and concating it with string result4 and storing in String result5*/

String result5 = result4 + ” ” +adverbs[randomNum];

//returning the final string

return result5;

}

public static void main(String[] args)

{

String Cannedmsg = shoutOutCannedMessage();

System.out.println(“Message that is returned from shoutOutCannedMessage() method : “+ Cannedmsg);

String Randommsg = shoutOutRandomMessage();

System.out.println(“Message that is returned from shoutOutRandomMessage() method : “+ Randommsg);

}

}

/*For better understanding output screenshot is attaced here*/

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?