Question

In: Computer Science

Project 3 Details The purpose of this project is to give you experience with creating and...

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:

  1. say hello to the user.
  2. say it's name
  3. say what its favorite day of the week and hobby is.
  4. say what its quirk is
  5. ask the user about themselves.

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:

  1. Main.java (class name Main)
  2. Chatbot.java (class name Chatbot)
  3. Memory.java (class name Memory)

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:

  1. A String called name
  2. A String called favoriteHobby
  3. A String called favoriteDOTW (day of the week)
  4. A String called quirk
  5. A double called height (we'll assume this represents height in feet).
  6. A double called weight (we'll assume this represents weight in pounds)
  7. A public set and get function for each variable. (That's 12 functions in total.)
    • As all instance variables in Memory will be private, ChatBots will check their memory using their individual memory object's get and set functions.

The Chatbot class will contain the following:

  1. A Memory object that will be used to store each Chatbot instance's memories.
  2. A public constructor function called Chatbot().
    1. In this function, programmatically assign values to the chatbot's memory object. In other words, hard-code the values here. Use the memory object's "set" functions to give throw-away values to each Memory variable. I don't really care what name, height, weight favorite day, etc. you type in. (We'll do something more interesting in a future project.)
  3. A public function called interact(String userMessage)
    • For now, all this function will do is call each of the "reply" functions (listed below) one after the other. That is all.
  4. A private function called replyHello().
    • This function will print a simple hello message to the user.
  5. A private function called replyName()
    • This function will contain a System.out.print message that tells the user the chatbot's name.
  6. A private function called replyFavoriteThings()
    • This function will contain a System.out.print message that tells the user about the chatbot's favorite things (favorite hobby and day of the week).
  7. A private function called replyQuirk()
    • This function will contain a System.out.print message that tells the user the chatbot's quirk.
  8. A private function called replyAskAboutUser()
    • This function will contain a System.out.print message that asks the user to tell it about themselves.

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

  • Experience with creating classes and objects.
  • Experience with using get and set functions

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:

  • 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 complicated 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 if's), put in comments to explain what 's going on.

Rubric

  • All instance variables private: 2 pts
  • Memory class includes get and set functions for each of its instance variables
  • Chatbot class implemented correctly, and includes a Memory object as an instance variable
  • Main function has a a chatbot created, with it's interact function called
  • Proper commenting

Solutions

Expert Solution

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?

----------------------------------------------------------------------------------------------------


Related Solutions

CVP Modeling project The purpose of this project is to give you experience creating a profitability...
CVP Modeling project The purpose of this project is to give you experience creating a profitability analysis that can be used to determine the effects of changing business conditions on a client's financial position. Managers often want to know the production level where profits earned from a product cover the cost of resources used to create it. Break-even analysis is how we determine this level. The point at which total sales revenues covers the costs of committed resources is called...
Purpose This project is meant to give you experience with sorting, binary searching, and Big-Oh complexity....
Purpose This project is meant to give you experience with sorting, binary searching, and Big-Oh complexity. Objective "Write in Java please" Your goal is to take a book, as a large text file, and build a digital “concordance”. A concordance is like an index for a book in that it contains entries for words in the book, but it also includes passages from the book containing that word. For example, a query for the word Dormouse in Alice in Wonderland...
The purpose of this exercise is to give you experience in writing condition-controlled loops. Create a...
The purpose of this exercise is to give you experience in writing condition-controlled loops. Create a code in Python that will print monthly loan amortization schedule given the loan amount (P), APR i.e. Annual Percentage Rate (r=APR in %/12), loan terms in number of months (n). Please use these formulas: Monthly Payment (A) = P * ((r * (1 + r)**n)/(((1+r)**n)-1))            Monthly Interest Pmt (mIP)= r * Total Remaining Balance Monthly Principal Pmt (mPP) = A –...
Purpose: This lab will give you experience modifying an existing ADT. Lab Main Task 1: Modify...
Purpose: This lab will give you experience modifying an existing ADT. Lab Main Task 1: Modify the ListInterface Java interface source code given below. Change the name of ListInterface to ComparableListInterface, and have ComparableListInterface inherit from the built-in Java interface Comparable. Note that Comparable has a method compareTo(). compareTo() must be used in programming logic you will write in a method called isInAscendingOrder() (more about isInAscendingOrder() is mentioned further down in the lab description). You can find a brief summary...
Purpose This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and...
Purpose This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and chmod(), perror(), and command line arguments. Program Write a C++ program that will allow you to add messages to a file that has NO permissions for any user. A Unix system has many files that have sensitive information in them. Permissions help keep these files secure. Some files can be publicly read, but can not be altered by a regular user (ex.: /etc/passwd). Other...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability to identify emerging ethical issues in business, interpret the multitude of perspectives inherent in your case study, and model appropriate behaviour by recommending specific solutions. How to Proceed Select a case. It can be one of the textbook cases that we have not discussed during the course. It can also come from the outside world, perhaps a case you have been following in the...
3. What are the blood vessels of the body? Give brief details about ONE type. Give...
3. What are the blood vessels of the body? Give brief details about ONE type. Give only the essential information.
Create a project plan on the game or application you are creating. The project plan should...
Create a project plan on the game or application you are creating. The project plan should include the following: A description of the game or application The IDE or game engine your plan to use to create the game or app and information on how you are going to develop the game or app If you choose to create a game, how are you going to approach the game design and game development process or if you choose an application...
Individual project details: 1. This project is to be a 2-3 page written document (plus citation...
Individual project details: 1. This project is to be a 2-3 page written document (plus citation page) answer the two questions outlined below. Understand your audience and their knowledge level so do not take the time to explain those concepts already known. There is wide latitude on how to approach the subject area and it will be necessary to know the subject matter well for a concise analysis along with the ability to discern important data from just information in...
Lab 3 Java Classes and Memory Management Multi-file Project In this lab you will gain experience...
Lab 3 Java Classes and Memory Management Multi-file Project In this lab you will gain experience using classes and arrays of classes. Use the following as the beginning of a student abstract data type. public class Student { private String fName ; private String lName ; private double[] grades; } This class should be in the package com.csc241. Write a program that prompts a user for a total number of students and dynamically allocates memory for just that number of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT