In: Computer Science
Project 3
Details
The purpose of this project is to give you experience with creating and using custom objects. In it, you will make a couple custom classes that work in tandem with each other, and call them in your main function.
For this project we'll be making something kind of like the Chatbot java file we made in class. You will create a Chatbot class that will contain a number of variables and functions.
As you can imagine, a real conversation with a chatbot would be boring if it couldn't remember anything. For this reason, you'll create a Memory class. The Memory class will contain variables for things a chatbot would want to remember. This will include it's name, height, favorite topic, etc. Your Chatbot class will contain a memory object that you will have to set up.
Objective
You will create the structure for a Chatbot. This includes a class to define and interact with the chatbot, and a class that will act as the chatbot's memory. You will create a chatbot object from main, and have it say the following things in sequence:
The chatbot will:
There will be no human interaction for this assignment. You will hard-code all values.
Instructions
You will create three java classes for this project:
Using what you've learned about making classes, you will create the three java files mentioned above. (Note that any instance variable's you make need to have their accessibility set to private.)
The Memory class will contain the following:
The Chatbot class will contain the following:
In the Main class, create a Chatbot object in your main function. Next, call that chatbot's interact function. That's all you'll do in main.
Goals
Sample Runs
Sample Program Run (note there is NO user input)
Hello there!
My name is Smithy!
I absolutely love Mondays and drawing things!
People say I'm very happy.
What about you? Can you tell me about yourself?
Other Requirements
Commenting Standards:
Rubric
Please find the below classes with the comments for each method. I have provided Name and number in the comments of each class, You may need to provide your name and number.
Memory Class:
-------------------------------------------------------------------------
/*
* Name:
* Number:
* Description: This is the Memory class. This will have all the
private
* variables to store the user information and getter/setter methods
to
* remember user information.
*
*/
public class Memory {
private String name;
private String favoriteHobby;
private String favoriteDOTW;
private String quirk;
private double height;
private double weight;
/**
* This is getter method to get the Name of the
user.
* @return the name
*/
public String getName() {
return name;
}
/**
* This is setter method to set the Name of the
user.
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* This is getter method to get the Favorite hobby of
the user.
* @return the favoriteHobby
*/
public String getFavoriteHobby() {
return favoriteHobby;
}
/**
* This is setter method to set the Favorite hobby of
the user.
* @param favoriteHobby the favoriteHobby to set
*/
public void setFavoriteHobby(String favoriteHobby)
{
this.favoriteHobby =
favoriteHobby;
}
/**
* This is getter method to get the "Favorite day of
the week" of the user.
* @return the favoriteDOTW
*/
public String getFavoriteDOTW() {
return favoriteDOTW;
}
/**
* This is setter method to set the "Favorite day of
hte week" of the user.
* @param favoriteDOTW the favoriteDOTW to set
*/
public void setFavoriteDOTW(String favoriteDOTW)
{
this.favoriteDOTW =
favoriteDOTW;
}
/**
* This is getter method to get the quirk of the
user.
* @return the quirk
*/
public String getQuirk() {
return quirk;
}
/**
* This is setter method to set the quirk of the
user.
* @param quirk the quirk to set
*/
public void setQuirk(String quirk) {
this.quirk = quirk;
}
/**
* This is getter method to get the height of the
user.
* @return the height
*/
public double getHeight() {
return height;
}
/**
* This is setter method to set the height of the
user.
* @param height the height to set
*/
public void setHeight(double height) {
this.height = height;
}
/**
* This is getter method to get the weight of the
user.
* @return the weight
*/
public double getWeight() {
return weight;
}
/**
* This is setter method to set the weight of the
user.
* @param weight the weight to set
*/
public void setWeight(double weight) {
this.weight = weight;
}
}
--------------------------------------------------------------------------
Chatbot class
--------------------------------------------------------------------------
/*
* Name:
* Number:
* Description: This is the Chatbot class. This will set the
Memory
* object with the data of the user to remember.This also has the
reply to the
* User with hard-coded values through interact method.
*
*/
public class Chatbot {
Memory m = new Memory();
/**
* This is consrtuctor method for Chatbot class.
* It set values to the Memory object using Memory
object set functions.
*/
public Chatbot() {
super();
m.setName("John");
m.setHeight(5.6);
m.setWeight(55.0);
m.setFavoriteHobby("Listening
songs");
m.setQuirk("I am good");
m.setFavoriteDOTW("Sunday");
}
/**
* This interact Method takes a String argument which
is actually not used.
* It just calls the methods to print the Chatbot
information.
* @param userMessage
*/
public void interact(String userMessage)
{
replyHello();
replyName();
replyFavoriteThings();
replyQuirk();
replyAskAboutUser();
}
/*
* This method prints the greeting
words.
*/
private void replyHello()
{
System.out.println("Hello
there!");
}
/*
* This method prints the name of the
chatbot".
*/
private void replyName()
{
System.out.println("My name is
Smithy!");
}
/*
* This method prints the favorite things
of chatbot.
*/
private void replyFavoriteThings()
{
System.out.println("I absolutely
love Mondays and drawing things!");
}
/*
* This method prints the chtabot
quirk.
*/
private void replyQuirk()
{
System.out.println("People say I'm
very happy.");
}
/*
* This method prints the ask for user
info.
*/
private void replyAskAboutUser()
{
System.out.println("What about you?
Can you tell me about yourself?");
}
}
-------------------------------------------------------------------------------------
Main Class
-------------------------------------------------------------------------------------
/*
* Name:
* Number:
* Description: This is the Main class for running the chatbot
interaction.
* we just call the Chatbot class's interact method here to display
the chatbot information
*
*/
public class Main {
public static void main(String args[])
{
Chatbot cb = new Chatbot();
cb.interact("Hello");
}
}
------------------------------------------------------------------------------
Just need to run the Main class, It will display the below output.
Output:
-------------------------------------------------------------------------------
Hello there!
My name is Smithy!
I absolutely love Mondays and drawing things!
People say I'm very happy.
What about you? Can you tell me about yourself?
----------------------------------------------------------------------------------------------------