This programming project may be done individually or in groups of two. Keep in mind that you may not work with the same person on more than two of the programming projects. If you work with a teammate, hand in one copy of your code with both names on it. It is okay to get help from the TAs and/or the instructor if you get stuck, but you should try to do it on your own first.
For this project you will be writing a program similar to the one you wrote for the Talking Robot Lab. Read the entire project description thoroughly (including the Design and Implementation Suggestions section at the end!) before starting your implementation.
The current talking robot is operated by a remote control. Two buttons on the remote control represent asking the robot a question and getting the answer. If you press the first button, the robot asks, "What is your question?" Unfortunately, the robot, as currently implemented, does not know how to recognize questions. Instead, if you press the second button, the robot gives a randomly-chosen "answer" such as "Definitely!", "OK", or "No way!", without knowing what the question was.
You have been hired by the makers of the robot to help create a new and improved version. Your focus will be to improve its conversational skills by making its choice of answers depend on the content of the actual question asked. The robot will not be able to appropriately answer all possible questions (which would be very tough to do!), but it will be able to recognize a small number of predefined questions or phrases, like "What's the weather?" or "Is it time for lunch yet?", and be able to give a variety of randomly-chosen answers for each question or phrase.
The robot makers have hired a different team to implement the
"speech-to-text" part of the program, which hears the question and
translates it to a
Your job is to create software that
String representing a question from the
and generates a response to the question.
Basic Program Specification:
Q: What time is it? A: Time for a nap!or
User: What is my favorite class? Talking Robot: COMP 110, of course.
More Advanced Option: If your program requires a question to match one of your expected questions exactly, word-for-word, then your robot will fail to give an appropriate response when there are slight changes to the wording of the question. For example, one of your possible questions could be "Is it time for lunch yet?" If your program requires the question to match exactly, then it would not recognize the very similar question "Isn't it time for lunch yet?" As an alternative, you could look for certain keywords or phrases instead of whole questions; for example, check for the word "lunch" anywhere in the question or, for a different type of question, look for the word "Who" as the first word.
You may want to create a list or table similar to the design you developed for the Talking Robot lab that shows your various questions/statements (or, for the advanced alternative, phrases or keywords) and, for each one, the set of three (or more) possible answers. You should also decide on what response you will generate for unrecognizeable questions.
Develop your program using incremental development. At each step, add a little functionality that gets you closer to your end goal, and test it.
SpeechToTextStub, as a substitute for the "speech to text" software that will be written by the other group of programmers. Download the stub class and add it to your project. The stub class will merely return a randomly-chosen question from a list of possible questions you provide, not actually hear and return a question that a user asked.
What is a "stub" class? A "stub" class is a small, limited-functionality substitute for a real class, developed for testing purposes. Its purpose is to provide just enough functionality so that it can be used to test other classes, especially during development.
SpeechToTextStubclass documentation to see how to construct an object of that class and what methods it has. Modify your
mainfunction to construct a
SpeechToTextStubobject, and then register a set of questions (or statements) a user might ask with it, using the
SpeechToTextStubclass will ensure that you do not always get the same phrase?
Note: In Java, it is easier to compare numbers than strings. Numbers can be compared with the
==operator, whereas strings should be compared with the
isEqualsmethod. Compareif ( anInt == 1 )withif ( phraseString.equals("Who is it?") )
More Advanced Option: Rather than basing your logic on comparison of whole questions or phrase codes, base it on recognizing keywords or phrases within questions. A set of useful methods from the
Stringclass have been documented in this appendix. You will need a longer list of questions and more tests to show that:
- Your program can generate different answers at different times to the same question (part of the Basic Specifications).
- The answers do relate to the question; in other words, you aren't just generating any random answer without regard to the question (also part of the Basic Specifications).
- Similarly-worded questions, or questions containing certain key words or phrases (or certain key words only at the beginning or end of the question) generate the same set of responses.
To simulate having a
conversation with the robot, and to show that your robot gives
different answers at different times to the same questions, modify
main method code so that it will go through the
get-a-question, give-an-answer sequence many times (at least 15).
(You are required to use a loop for this, so you may want to
wait until after the Keep on Moving mini-lab to implement this last
step of your project.)
You can produce somewhat more controlled test cases by turning off the
randomization of questions returned by the speech-to-text module, and
instead adding repetitions of your questions as test cases. (Of course,
you will still have random behavior in the choice of answers.) With
question randomizing turned off, if you add your first question as a test case
six times before adding your second question, the speech-to-text module
will return your first question six times before returning your second
question. Once the module has returned all questions you added as test
cases, it will return "Unrecognized phrase", so you can test how your
program reacts to unrecognized questions by calling
getPhrase at least one more time than the number of test
cases you entered.
Submit to Moodle the external user documentation (README)
and the source code (
main class you created.