javachatbot

Chatbot class (service class) and chatbot client (application) class


ChatBot class:

A chatbot is a computer program designed to simulate an intelligent conversation with one or more humans. In this lab, we will establish the framework for our chatbot, which will be enhanced throughout the semester.

The ChatBot class will define a name field that identifies the chatbot (name your chatbot anything you like.) This will be an immutable field; Only an accessor method is required for the name field. The name field should be set in the default constructor.

The ChatBot class defines two additional methods, one returns an introductory message including the chatbot’s name. The other accepts a String and produces a String reply. At this point in time, the reply method always returns the same message.

This is what the UML diagram looks like

Chatbot (class or constructor)

minus (- private) name : String

plus (+ public) getName() : String

plus (+ public) introbot() : String

plus (+ public) public reply (userInput : String ) : String

ChatBot Client:

The client application will manage the chat between the end-used and the chatbot. The client is responsible for retrieving the end-user’s comment, passing it to the chatbot, and retrieving and displaying the chatbot’s response. The user’s or chatbot’s name should be used as the input prompt. Below is a sample run of the client:

Enter your name: Jeff

Hi! My name is mutebot

Jeff > hello

mutebot > I'm just learning to talk

THIS is my service class

/*
 * Java Car service class
 * @author blake
 * 2/13/2012
 */

public class Chatbot
{
    private final String name;
    private String introbot;
    private String reply;
    
    public Chatbot(String newName, String newIntrobot, String newReply)
    {
    name = newName;
    }
    
    
    public String getName()
    {
    return name;
    }
}

THIS is my application class

import java.util.Scanner;
public class ChatbotClient
{
   public static void main(String[] args)
    {
       Scanner input = new Scanner(System.in);
       System.out.println("What is your name? ");
       String name = input.nextLine();
       
       System.out.println("\nHi " + name + " My name is copbot");
       
       
         System.out.println(name);
         String reply = input.nextLine();
         
         System.out.println("/ncopbot" + "I'm just learning how to talk " );
    }
}

I am not exactly sure if this is exactly what the problem asked or required for, or if this is the way to do it.

I think the service class might be okay, but I am not too sure about the application class as that is where you would do your accessors, and mutators and those sort of things, I guess you just set up your fields and instances in the service class.


Solution

  • There are a few things to fix, but you're heading in the right direction.

    Your chatbot has a broken import line, but I assume that's just a copy/paste glitch.

    The instructions specified that the chatbot's name was read-only, but you have a setter method, so you probably don't want that. ;) Also, the UML describes "introbot" and "reply" as methods which return Strings, not String variables.

    Once you've made those changes, then you should be able to call those two methods from your chatbot client. Where you currently have "System.out.println" lines, these should be calls to the chatbot. For example, the fragment:

     "My name is copbot"
    

    should become something like

     "My name is " + myChatbot.getName()
    

    The reply(userInput : String) method should have the user input passed to it through the list of parameters. Its return value (also a String) can then be used to fill in the "I'm just learning how to talk" println.

    Good luck!