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:
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.
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.
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.