Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java Instructions As you will be reusing code from project three, you should be starting this project with the following three classes created and

image text in transcribed
image text in transcribed
image text in transcribed
in java
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Instructions As you will be reusing code from project three, you should be starting this project with the following three classes created and partially implemented: 1. Main.java (class name Main) 2. ChatBot.java (class name ChatBot) 3. Memory.java (class name Memory) In the event you need code to start this project with you can use the follwoing code as a starting point, or at least a point of reference: Project 3 ChatBot Answer.zip In quick review, the Memory class contains variables that represent important Information that a ChatBot would need to know. The ChatBot class contains logic for how a ChatBot can respond to a user (with various reply functions). The ChatBot class has a memory object as an instance variable. Main was originally used to create a single ChatBot and perform a single interaction with it. For this project, you will update the code to accept a whole sentence from the user in your Main class. Once you read in the sentence from the user, your ChatBot will search the sentence for any one of the following key words: hello name favorite quirk height weight If you find one of these key words, you'll have the chatbot reply with an appropriate response. The program will respond to the first word it finds in the sentence. In example, if you say "Hello there chatbot!"...the first word in the sentence the chatbot should respond to is the word "Hello." Specifically, it will respond with the replyHello function. If you instead say, "My name is Jared." then the ChatBot should respond with its own name. Specifically, it will respond with the replyName() function. If you say two keywords in one sentance, the chatbot should respond to the first keyword you find. So, if you say, "My name is Tim. Do you have favorite day of the week?" ...the ChatBot should respond to the word "name" and not the word "favorite." This is to simplify things for now. This checking of the users sentence will occur in the interact() function in ChatBot.java. Your program should loop in main, each time asking the user for a sentence. If the user types "exit" then the loop should end. You will make the following major changes to Main.java: 1. Keep the chatbot you created, but delete the call to your chatbot's interact() function 2. In the main function, after the chatbot you originally created. Create a scanner for input. 3. Following that, add the following into the main function: 1. A loop that loops until the user enters the exact string "exit" 2. Add a call to your chatbot's interact function in the loop. Pass in the user's String sentence as a parameter. You will make the following major changes to ChatBot.java: 1. Set the chatbot's name, favorite hobby, favorite dotw. quirk, height and weight to something meaningful in the ChatBot() constructor Tallowed hiller values for these before, but I expect actual values to be given now. 2. Add replyHeight() and reply Weight() functions to ChatBot.java. Add a System.out.print call to each, and have the chatbot say something for each. Be sure to use the get functions from the memory object to grab out the height and weight. 3. Modify interact(String user Message) function to: 1. look through the user's message to the chatbot to find a keyword. You'll want to review our slides on Strings from Week 7 for how to do this. 2. Store the keyword you found in a String variable. From there you can use ifs or a switch block to check if the value of the string equals any of the keywords mentioned earlier. 3. If the string you stored equals a keyword, print out that key words's reply function. 4. If the string you stored does not contain a keyword, just have the ChatBot respond with the replyAskAboutUser function Goals Get experience using and searching through Strings. . Get experience with loops . Get experience with Modifying an existing custom class. Sample Runs Sample Program Run (user input is underlined) Say something: What's you name? My name is Tim! Say something: Do you have a favorite hobby? I really like Reading and Mondays! Say something: Do you work? What about you? Care to tell me about yourself? Say something:... What about you? Care to tell me about yourself? Other Requirements Commenting Standards: Include javadoc comments for each function you make (including main(). Describe what each function is doing in their Javadoc comment. Include a Javadoc comment for your class. Include your name, n-number, and project name and description of what the class/project does in this comment. Include comments in your functions that explains complected pieces of code. If the code seems easy to understand then there's no need. But for hard to follow spots (i.e. multiple if's within it's). put in comments to explain what's going on. File Naming: Please name your project "n Project 4. Be sure to zip up your whole project and submit it here as 'n# Project 4.zip!" (Also be sure to include your WHOLE Eclipse project in the zip! Not just the Java fles! Main java - Cool File Viewer public class Main public static void main(Stringil arga) ChatBot bot - new ChatBot(); bot.interact(): }//end main function 17/end class me Main) & Memory.java - Cool File Viewer public class Memory private String name: private String favoritellobby! private String favoriteDOTW; private String quirk; private double height: private double weight: public String getName() return name //end function public String getFavoriteHobby return favorite Hobby: //end function public String getFavoriteDOTW() return favoriteDOTW; >//end function public String getQuirk() return quirky //end function public double getHeight() return height: >//end function public double getWeight () return weight; //end function memory.java - Cool Hile Viewer public double getweight() return weight: //end function public void setName(String name) this.name" name i//Notei 'this.name' refers to the instance variable. Just'name' refers to this function >//end function public void setFavoriteHobby (String favoriteHobby) this.favoritellobby - favoritelobby: 1//end function public void setFavoriteDOTW (String favoriteDOTW) this.tavoriteDOTW - favoriteDOTW; }//end function public void set Quirk(String quirk) this.quirk - quirky //end function public void setHeight (double height) this.height = height: 1//end function public void setWeight (double weight) this.weight-weight //end function 1 //end class ChatBot.java - Cool File Viewer public class ChatBot private Memory memory: public ChatBot () memory.setName("Tim"): memory.setFavoriteHobby ("Running"); memory.setFavoriteDOTW ("Friday"); memory.Bet Quirk(talkative"): memory.setHeight (5.5); memory.setWeight (150.0); //end constructor public void interact (String user Message) replyHellot): replyName(): replyFavoriteThings()! replyouink(): replyakAboutUser()1 }//end function private void replyHello() System.out.println("Good day to you, user!"); 1//end function private void replyName() System.out.println("My name 18" + memory.getName() + "!") }//end function private void replyFavoriteThings() memory.getFavoriteHobby + and memory.getFavoriteDOTW() + "!! System.out.println("I really like >//end function private void replyQuirk() ChatBot java - Cool File Viewer 17/end constructor public void interact (String replyHello ; replyName(); replyFavoriteThings(); replyQuirk() replyAskAboutUser(); //end function private void replyHello) System.out.println("Good day to you, user!") //end function private void replyName() System.out.println("My name 13" + memory.ge 37/end function }//end function private void replyFavoriteThings() + memory.getFavoriteDOTW) + 3! System.out.println("I really like " + memory.getFavorite Hobby () + " //end function private void replyQuirk() System.out.println("People say I'm a }//end function Oryget private void replyAskAboutUser() System.out.println("What about you? Care to tell me about yourself?" 37/end function Instructions As you will be reusing code from project three, you should be starting this project with the following three classes created and partially implemented: 1. Main.java (class name Main) 2. ChatBot.java (class name ChatBot) 3. Memory.java (class name Memory) In the event you need code to start this project with you can use the follwoing code as a starting point, or at least a point of reference: Project 3 ChatBot Answer.zip In quick review, the Memory class contains variables that represent important Information that a ChatBot would need to know. The ChatBot class contains logic for how a ChatBot can respond to a user (with various reply functions). The ChatBot class has a memory object as an instance variable. Main was originally used to create a single ChatBot and perform a single interaction with it. For this project, you will update the code to accept a whole sentence from the user in your Main class. Once you read in the sentence from the user, your ChatBot will search the sentence for any one of the following key words: hello name favorite quirk height weight If you find one of these key words, you'll have the chatbot reply with an appropriate response. The program will respond to the first word it finds in the sentence. In example, if you say "Hello there chatbot!"...the first word in the sentence the chatbot should respond to is the word "Hello." Specifically, it will respond with the replyHello function. If you instead say, "My name is Jared." then the ChatBot should respond with its own name. Specifically, it will respond with the replyName() function. If you say two keywords in one sentance, the chatbot should respond to the first keyword you find. So, if you say, "My name is Tim. Do you have favorite day of the week?" ...the ChatBot should respond to the word "name" and not the word "favorite." This is to simplify things for now. This checking of the users sentence will occur in the interact() function in ChatBot.java. Your program should loop in main, each time asking the user for a sentence. If the user types "exit" then the loop should end. You will make the following major changes to Main.java: 1. Keep the chatbot you created, but delete the call to your chatbot's interact() function 2. In the main function, after the chatbot you originally created. Create a scanner for input. 3. Following that, add the following into the main function: 1. A loop that loops until the user enters the exact string "exit" 2. Add a call to your chatbot's interact function in the loop. Pass in the user's String sentence as a parameter. You will make the following major changes to ChatBot.java: 1. Set the chatbot's name, favorite hobby, favorite dotw. quirk, height and weight to something meaningful in the ChatBot() constructor Tallowed hiller values for these before, but I expect actual values to be given now. 2. Add replyHeight() and reply Weight() functions to ChatBot.java. Add a System.out.print call to each, and have the chatbot say something for each. Be sure to use the get functions from the memory object to grab out the height and weight. 3. Modify interact(String user Message) function to: 1. look through the user's message to the chatbot to find a keyword. You'll want to review our slides on Strings from Week 7 for how to do this. 2. Store the keyword you found in a String variable. From there you can use ifs or a switch block to check if the value of the string equals any of the keywords mentioned earlier. 3. If the string you stored equals a keyword, print out that key words's reply function. 4. If the string you stored does not contain a keyword, just have the ChatBot respond with the replyAskAboutUser function Goals Get experience using and searching through Strings. . Get experience with loops . Get experience with Modifying an existing custom class. Sample Runs Sample Program Run (user input is underlined) Say something: What's you name? My name is Tim! Say something: Do you have a favorite hobby? I really like Reading and Mondays! Say something: Do you work? What about you? Care to tell me about yourself? Say something:... What about you? Care to tell me about yourself? Other Requirements Commenting Standards: Include javadoc comments for each function you make (including main(). Describe what each function is doing in their Javadoc comment. Include a Javadoc comment for your class. Include your name, n-number, and project name and description of what the class/project does in this comment. Include comments in your functions that explains complected pieces of code. If the code seems easy to understand then there's no need. But for hard to follow spots (i.e. multiple if's within it's). put in comments to explain what's going on. File Naming: Please name your project "n Project 4. Be sure to zip up your whole project and submit it here as 'n# Project 4.zip!" (Also be sure to include your WHOLE Eclipse project in the zip! Not just the Java fles! Main java - Cool File Viewer public class Main public static void main(Stringil arga) ChatBot bot - new ChatBot(); bot.interact(): }//end main function 17/end class me Main) & Memory.java - Cool File Viewer public class Memory private String name: private String favoritellobby! private String favoriteDOTW; private String quirk; private double height: private double weight: public String getName() return name //end function public String getFavoriteHobby return favorite Hobby: //end function public String getFavoriteDOTW() return favoriteDOTW; >//end function public String getQuirk() return quirky //end function public double getHeight() return height: >//end function public double getWeight () return weight; //end function memory.java - Cool Hile Viewer public double getweight() return weight: //end function public void setName(String name) this.name" name i//Notei 'this.name' refers to the instance variable. Just'name' refers to this function >//end function public void setFavoriteHobby (String favoriteHobby) this.favoritellobby - favoritelobby: 1//end function public void setFavoriteDOTW (String favoriteDOTW) this.tavoriteDOTW - favoriteDOTW; }//end function public void set Quirk(String quirk) this.quirk - quirky //end function public void setHeight (double height) this.height = height: 1//end function public void setWeight (double weight) this.weight-weight //end function 1 //end class ChatBot.java - Cool File Viewer public class ChatBot private Memory memory: public ChatBot () memory.setName("Tim"): memory.setFavoriteHobby ("Running"); memory.setFavoriteDOTW ("Friday"); memory.Bet Quirk(talkative"): memory.setHeight (5.5); memory.setWeight (150.0); //end constructor public void interact (String user Message) replyHellot): replyName(): replyFavoriteThings()! replyouink(): replyakAboutUser()1 }//end function private void replyHello() System.out.println("Good day to you, user!"); 1//end function private void replyName() System.out.println("My name 18" + memory.getName() + "!") }//end function private void replyFavoriteThings() memory.getFavoriteHobby + and memory.getFavoriteDOTW() + "!! System.out.println("I really like >//end function private void replyQuirk() ChatBot java - Cool File Viewer 17/end constructor public void interact (String replyHello ; replyName(); replyFavoriteThings(); replyQuirk() replyAskAboutUser(); //end function private void replyHello) System.out.println("Good day to you, user!") //end function private void replyName() System.out.println("My name 13" + memory.ge 37/end function }//end function private void replyFavoriteThings() + memory.getFavoriteDOTW) + 3! System.out.println("I really like " + memory.getFavorite Hobby () + " //end function private void replyQuirk() System.out.println("People say I'm a }//end function Oryget private void replyAskAboutUser() System.out.println("What about you? Care to tell me about yourself?" 37/end function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions