Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I recently got a challenging java homework. Could you help giving me examples and explanations? Thanks The requirement of the hw is below : Do

I recently got a challenging java homework. Could you help giving me examples and explanations? Thanks

The requirement of the hw is below :

Do a java class called Conversation

The Conversation class must define these object variables:

String tagWord; // substring to search for in a statement. 

//true if the statement response is constructed by extracting before tagWord,

// false is the response is constructed by extracting after.

boolean extractBefore; String responseBefore; //text to put before statement extract in the response String responseAfter; //text to put after statement extract in the response String default0Mod3; //Default response if wordCount(statement) = 0 % 3 String default1Mod3 //Default response if wordCount(statement) = 1 % 3 String default2Mod3 //Default response if wordCount(statement) = 2 % 3 

The Conversation class must define getter and setter methods for all the object variables, appropriate constructors, and these object methods:

//returns the word count of statement_, where a word is defined as any group

// of symbols, delimited by white space, containing at least one alphanumeric

// character. In this context, white space includes start and end of text,

// and/or one or more of these characters: ' ', \t, .

int wordCount(statement) { ...

//Returns a response to statement_. String response(String statement_) { ... //Transform statement_ by exchanging 1st & 2nd person pronouns // and possessives. Called from the response object method. String changePerson(String statement_) { ... //Returns an informative display of the state of all the object variables String toString() { ... 

My starting code:

public class Conversation { // substring to search for in a statement. // like "because", on the midterm programming String tagWord; //true if the statement response is constructed by extracting before tagWord, // false is the response is constructed by extracting after. boolean extractBefore; String responseBefore; //text to put before statement extract in the response String responseAfter; //text to put after statement extract in the response String default0Mod3; //Default response if wordCount(statement) = 0 % 3  String default1Mod3; //Default response if wordCount(statement) = 1 % 3 String default2Mod3; //Default response if wordCount(statement) = 2 % 3 //getter method for tagWord String getTagWord () { return this.tagWord; } //getTagWord String setTagWord(String tagWord) { String oldTagWord = this.tagWord; this.tagWord = tagWord; return oldTagWord; }//setTagWord() //returns the word count of statement_, where a word is defined as any group // of symbols, delimited by white space, containing at least one alphanumeric // character. In this context, white space includes start and end of text, // and/or one or more of these characters: ' ', \t, . int countWords(String statement_) { /* * [abc]+ == and it means one or more a, b, or c * (a|b) == a or b * are white space definition includes -- new line and * \t tab * String s = "This\tis \ta gap." * come up with a regular expression, using [], or perhaps |, * such that s.split() == 4 */ int = wordCount = statement_.split(/**/); return wordCount; } //Returns a response to statement_. String respond(String statement_) { } } //Conversation( 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

6. Could the problems have been anticipated and avoided? How?

Answered: 1 week ago