Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Identify multiple keywords in the input, and respond with both values (HashMap)  RSS feed

 
Chan Duller
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Identify multiple keywords in the input, and respond with both values (HashMap). Someone might type in "my windows PC crashed". The SupportSystem class should print out responses for both "windows" and "crashed". You should not have the Responder class do any printing. Also, be sure to print each response out only once (i.e. typing in "crash crashed" should not cause the same response to be printed twice).

 
Tim Cooke
Marshal
Posts: 3859
233
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting code it's always best to UseCodeTags to make you code nice and easy to read. I've added them for you this time, see how much better it looks?

Ok, so back to your question. Well, you appear to have forgotten to ask any question at all. All I see is what I assume is your school assignment, and what appears to be someone else's solution to it. What's going on?
 
Chan Duller
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the code tags. There is no solution to it yet. I did the first part, which was to make a second HashMap with synonyms of keywords from the first. However, I cannot figure out where to start for the second part where we need to be able to get both values (responses) returned if the prompt includes two keywords.
 
Chan Duller
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is what I have added, but I am getting an error when I try to use the add feature of ArrayLists. Any suggestions?
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In future it would be very helpful if you explained your problem a bit more fully. "Getting an error" isn't very specific, in fact it doesn't tell us anything at all. However I can see by looking at your code that you aren't saying (in the code) what you want to add to the list.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chan Duller wrote:
This is what I have added, but I am getting an error when I try to use the add feature of ArrayLists. Any suggestions?


The ArrayList class does not have an add() method that takes no-arguments. It does have an add() method that takes one argument, and it also has an add() method that takes two arguments. Perhaps you meant to call one of those methods instead?

Henry
 
Chan Duller
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the update, but now I am getting the following error: incompatible types: java.util.ArrayList<java.lang.String> cannot be converted to java.lang.String.
 
Chan Duller
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just figured out that it is because it expects a String return type. My only question is, how do I work it when the default response is in String form, and the other is in ArrayList form?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you just want to return response instead of responses?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!