Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Activity 4, we're teaching Magpie to respond to phrases, rather than just keywords. Statements like I like CodeHS, I like programming, I like
In Activity 4, we're teaching Magpie to respond to phrases, rather than just keywords. Statements like "I like CodeHS," "I like programming," "I like popsicles" all have the form of "I like x." A response to this could be "What do you like about x?" Exploration The Magpie class in the starter code here has revisions to handle phrases like this. Test Magpie by telling it "I want to build a robot," "Do you like me?" and "You confuse me." Exercises 1. Change the code so the response to "I want x" is "Would you really be happy if you had x?" 2. Change the code so the response to "1 x you" is "Why do you x me?" Then, find an example of a statement that doesn't make sense with this response. How could you improve it? Extra Credit Try adding a new keyphrase structure to Magpie. Here are some examples: -"Have you x?" -> "I haven't x, have you?" - "I'm going to x." -> "Good luck with x ! It sounds fun." New MagpieRunner.java Magpie.java 2.1.7 Activity 4: Responses that Transform Statements 1 import java.util.Scanner; 2 3 public class Magpie Runner 4- { 5 6 7 8 9 10 public static void main(String[] args). { Magpie magpie = new Magpie(); System.out.println("M> " + magpie.greeting()); Scanner scanner = new Scanner(System.in); String statement = scanner.nextLine(); while (!statement.equals("Bye")) 11 12 13- { 14 15 16 17 18 } 19 20 21 System.out.println("M > " + magpie.getResponse(statement)); statement = scanner.nextLine(); scanner.close(); Submit + Continue Save Output Docs Assignment Grade More 5 points Status: Not Submitted In Activity 4, we're teaching Magpie to respond to phrases, rather than just keywords. Statements like "I like CodeHS," "I like programming," "I like popsicles" all have the form of "I like x." A response to this could be "What do you like about x?" Exploration The Magpie class in the starter code here has revisions to handle phrases like this. Test Magpie by telling it "I want to build a robot," "Do you like me?" and "You confuse me." Exercises 1. Change the code so the response to "I want x " is "Would you really be happy if you had x?" 2. Change the code so the response to "I x you" is "Why do you x me?" Then, find an example of a statement that doesn't make sense with this response. How could you improve it? Extra Credit Try adding a new keyphrase structure to Magpie. Here are some examples: - "Have you x?" -> "I haven't x, have you?" - "I'm going to x." -> "Good luck with x ! It sounds fun." 1 2- { 3- 4 5 6 7 New + MagpieRunner.java Magpie.java 2.1.7 Activity 4: Responses that Transform Statements public class Magpie * Gets a default greeting. * @return String */ public String greeting() Submit + Continue Save Output Docs Assignment Grade More 5 points Status: Not Submitted G /** 8 { 9 return "Hey, what's up?"; 10 } 11 12 /** 13 14 15 16 17 18 19- { 20 21 22- { 23 24 } 25- 26 27 28 29 30 31 32 33 } 34 35 36 37 * Resturns a response to a user statement @param statement * @return String *1 public String getResponse(String statement) String response = ""; if (findKeyword(statement, "no") >= 0) response = "Don't be so negative!"; else if ( findKeyword(statement, "mother") >= 0 || findKeyword(statement, "brother") >= 0 || findKeyword(statement, "sister") >= 0 || findKeyword(statement, "father") >= 0 response = "Tell me more about your family!"; else if ( findKeyword(statement, "weather") >= 0 || findKeyword(statement, "sun") >= 0 || findKeyword(statement, "rain") >= 0 Extra Credit Try adding a new keyphrase structure to Magpie. Here are some examples: -"Have you x?" -> "I haven't x, have you?" - "I'm going to x." -> "Good luck with x! It sounds fun." In Activity 4, we're teaching Magpie to respond to phrases, rather than just keywords. Statements like "I like CodeHS," "I like programming," "I like popsicles" all have the form of "I like x." A response to this could be "What do you like about x?" Exploration The Magpie class in the starter code here has revisions to handle phrases like this. Test Magpie by telling it "I want to build a robot," "Do you like me?" and "You confuse me." Exercises 1. Change the code so the response to "I want x " is "Would you really be happy if you had x?" 2. Change the code so the response to "I x you" is "Why do you x me?" Then, find an example of a statement that doesn't make sense with this response. How could you improve it? 38 39- { 40 41 42 43- { 44 response = "The weather here is really nice."; else if (findKeyword(statement, "I want to", 0) >= 0) response = transformIWantToStatement (statement); 45 46
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres an code implementation of the Magpie class in Java incorporating the changes requested in the exercises import javautilScanner public class Magpie public String getResponseString statement Strin...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started