Click to See Complete Forum and Search --> : need help with writing a program for a course


sweetgal
10-23-2006, 09:18 AM
hi everyone,
i am writing a program for class.. but it requires a class to be written. The program is going to act as a simple pyschotherapist and i am having such a hard time figuring out the class.
I have to store each set of keywords and matching responses into a Dialog object, where the dialog is the following class:

class Dialog {
private String[] keywords;
private String[] responses;
private int keywordCount = 0;
private int responseCount = 0;

public Dialog(int numKeywords, int numResponses) {
String[] keywords = new keywords[numKeywords];
String[] responses = new responses[numResponses];
}

//Adds the specified keyword
public void addKeyword(String keywords) {
keywordCount++;
}

//Ads the specified response
public void addResponse(String[] responses) {
responseCount++;
}

//Searches input for a matching keyword. If one is found,
//returns a randomly chosen response. If no keyword is found,
//returns null.
public String getResponse(String input) {
String chosenResponse = null;
int i, j;
if (


this is all i have so far..and the main method will create an array named dialogs containing 13 dialog objects.Each object will be individually created and stored into the arrary. For example, the following statements create a Dialog object and store it into position 0 of the array:
dialogs[0] = new Dialog(1, );
dialogs[0].addKeyword("always");
dialogs[0].addResponse("Can you think of a specific example?");

The after reading the user's input, the main method will cal the getResponse method once for each object in the array. When getResponse returns a non-null response, main will print this response and break out of the loop.

i need help finishing the class..

agent_x91
10-30-2006, 03:13 AM
Sorry, could you elaborate slightly? Am I right in thinking that your Dialog objects will search for specific keywords and give a random response if any of the keywords are found?

In that case, why do you require an array of different Dialog objects? What are you planning to use them for?


Meanwhile, some points:


//Adds the specified keyword
public void addKeyword(String keywords) {
keywordCount++;
}


That method increments the number of keywords, however it doesn't appear to actually to the vital job of adding the keyword. Try this:


//Adds the specified keyword
public void addKeyword(String keyword)
{
keywords[keywordCount++]=keyword;
}



A similar measure should be taken to correct the addReponse() method.

sweetgal
10-30-2006, 07:55 PM
Ahh yes i forgot to give in the main details about the program, sorry. But its ok for now, i figured it out. Thanks though.

agent_x91
10-31-2006, 05:07 AM
Okay good luck.