ML - Intro to Magpie Class (Lesson)
Intro to Magpie Class
Introduction
In this lesson we will begin writing our chatbot Magpie. You will be provided with some starter code to alter. At the end of this lab you will submit a finished Magpie.java file.
Before we begin, we need to review the String method trim(). Investigate the Java API Links to an external site. and look at the String class. Find the method trim().
Click below to find out if you know the answer to the question.
Magpie Class
Click below to begin the Magpie Class Lab.
This lab is from AP Central Links to an external site..
Adding to Magpie Class
Open the Magpie.java and MagpieRunner.java classes in Dr. Java.
Alter the code:
1. Have it respond “Tell me more about your pets” when the statement contains the word “dog” or “cat”. For example, a possible statement and response would be:
statement: I like my cat Mittens.
response: Tell me more about your pets.2. Have it respond favorably when it sees the name of your teacher. Be sure to use appropriate pronouns! For example, a possible statement and response would be:
statement: Mrs. Arrington is telling us about robotics.
response: She sounds like a good teacher.
3. Have the code check that the statement has at least one character. You can do this by using the trim method to remove spaces from the beginning and end, and then checking the length of the trimmed string. If there are no characters, the response should tell the user to enter something. For example, a possible statement and response would be:
statement:
response: Say something, please.
4. Add two more noncommittal responses to the possible random responses.
5. Pick 3 more keywords, such as “no” and “brother” and edit the getResponse method to respond to each of these.
These changes will be part of the final Magpie.java file that you will submit at the end of this lab.
IMAGES CREATED BY GAVS