Conversational Computing

Take at least 10 minutes to brainstorm with your partner a topic for your conversational computer program. A program is not going to be able to talk about a lot of topics, but you can write it so it can talk for a few minutes on a specific topic. Some ideas to get you started would be a current popular movie, or book, or public event; a help desk for a specific product or service; a tutor for one subject; my only requirement is that the conversation has to be in English (because I really can't converse in any other language).

Once you have a topic, write about 4-6 lines of back and forth dialog. Think about how we humans determine what to say next. Are there keywords we listen for to know how to respond? I put those in italic.

Topic: Iron Dragon Help Desk (Iron Dragon is a board game) see image.

Have the TA approve your plan on paper BEFORE you start to code it!

Once you have a starting (if stilted) conversation, write code that will respond to your specific keywords. Remember that this lab is about using the String methods, writing your own methods, and using loops and if statements. If you have multiple responses that are equally good, such as in my first block for Carol above, you can use a random number to choose one.

Check yourself:

  • Was your plan approved?
  • Are your communications with your user appropriate and helpful?
  • Are you using String methods?
  • Did you use a loop at least once?
  • Does your main method read like a concise list of necessary actions?
  • Are all methods documented with comments?

A Better Conversationalist

Expand your plan to include at least two branches. In my example, I would add two more common rules questions that Carol can answer. The program must allow for human variation in the order of topics brought up. In other words, your program needs to listen for keywords then act appropriately.

Expand your program according to your plan. Test it extensively. Pay close attention, and take notes, for where it fails.

Conversational Sentinel Value

Computer science has the concept of a sentinel value. A value that is not part of the input data but that indicates the end of the input data. If we were writing a program asking the user for test scores to be averaged, we could set a sentinel value of -1 for the user to enter to indicate they are done entering numbers. We have a natural sentinel value in conversation: Bye!

Create a loop in your main method that keeps the conversation going until the human types Bye or any reasonable variation that you want to code in. As long as the conversation is still going continue to alternate between getting the human response and providing the computer response. This loop should contain only two method calls and nothing else. Your method for getting the human input is small and simple, but the method that generates the computer conversation is more complex and should probably call (or invoke) several methods under certain conditions.

Arrays of Response Choices

Now that you know about Arrays, you can add them to your project! One way humans know when they are chatting with a bot is that the responses start to repeat and do not have the natural variations of human conversation. Choose at least two response situations for the computer and create an array of possible responses. Use a random number generator based on the number of items in the array to choose which response the program will use.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.