Skip to content

dqhieuse/Simple-Chat-Bot-with-Java

Repository files navigation

Simple Chat Bot with Java 🤖

A simple chat bot project written in Java that helps users interact through a command-line interface with interesting features like age guessing, number counting, and programming knowledge testing.

🎯 Project Overview

This is an educational chat bot designed to help programming beginners. The bot can:

  • Greet and remember user names
  • Guess age through mathematical algorithms
  • Count from 0 to any number the user inputs
  • Test programming knowledge through multiple-choice questions

🚀 Key Features

1. Friendly Greeting

  • Bot introduces itself with name and creation year
  • Asks for and remembers user's name

2. Smart Age Guessing

  • Uses Chinese Remainder Theorem algorithm
  • User inputs remainders when dividing age by 3, 5, and 7
  • Bot calculates and accurately guesses the age

3. Counting Demonstration

  • Counts from 0 to user-specified number
  • Displays each number sequentially

4. Programming Knowledge Quiz

  • Presents multiple-choice questions about programming
  • Repeats questions until user answers correctly
  • Congratulates upon completion

🛠️ Technologies Used

  • Language: Java
  • Framework: Standard Java (no external frameworks)
  • I/O: Scanner for user input
  • Testing: JUnit for unit testing

📁 Project Structure

Simple-Chat-Bot-with-Java/
├── Simple Chat Bot with Java/
│   ├── task/
│   │   ├── src/
│   │   │   └── bot/
│   │   │       └── SimpleBot.java     # Main file containing bot logic
│   │   ├── test/
│   │   │   └── Tests.java             # Test cases file
│   │   └── build/                     # Build and reports directory
│   ├── Meet your chat bot/
│   │   └── task.html                  # Stage 1 instructions
│   ├── Teach your bot to count/
│   │   └── task.html                  # Stage 2 instructions
│   └── Play a simple quiz together/
│       └── task.html                  # Stage 3 instructions
└── README.md

🏃‍♂️ How to Run

System Requirements

  • Java JDK 8 or higher
  • Java IDE (IntelliJ IDEA, Eclipse, or VS Code)

Steps to Execute

  1. Clone repository

    git clone https://github.com/hieudq05/Simple-Chat-Bot-with-Java.git
    cd Simple-Chat-Bot-with-Java
  2. Compile and run

    cd "Simple Chat Bot with Java/task/src"
    javac bot/SimpleBot.java
    java bot.SimpleBot
  3. Or use IDE

    • Open project in IDE
    • Navigate to SimpleBot.java
    • Run the main file

💬 Example Interaction

Hello! My name is Aid.
I was created in 2018.
Please, remind me your name.
> John
What a great name you have, John!
Let me guess your age.
Enter remainders of dividing your age by 3, 5 and 7.
> 1
> 0
> 3
Your age is 25; that's a good time to start programming!
Now I will prove to you that I can count to any number you want.
> 5
0!
1!
2!
3!
4!
5!
Let's test your programming knowledge.
Why do we use methods?
1. To repeat a statement multiple times.
2. To decompose a program into several small subroutines.
3. To determine the execution time of a program.
4. To interrupt the execution of a program.
> 2
Congratulations, have a nice day!

🧪 Testing

The project includes test cases to ensure accuracy:

# Run tests (if using Gradle)
./gradlew test

# Or run Tests.java directly
javac test/Tests.java
java Tests

📚 How It Works

Age Guessing Algorithm

The bot uses the Chinese Remainder Theorem to guess age:

int age = (rem3 * 70 + rem5 * 21 + rem7 * 15) % 105;

Program Flow

  1. greet() - Greets and gets user name
  2. remindName() - Remembers and responds to name
  3. guessAge() - Guesses age through algorithm
  4. count() - Counts numbers as requested
  5. test() - Tests programming knowledge
  6. end() - Ends with congratulations

🎓 Learning Objectives

This project demonstrates:

  • Method decomposition in Java programming
  • User input handling with Scanner
  • Mathematical algorithms implementation
  • Loop structures and control flow
  • Basic testing practices

🤝 Contributing

All contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

🔧 Development Notes

  • Project is built in stages (incremental development)
  • Each stage has its own task.html file with detailed instructions
  • Code is well-organized with separate methods for each functionality
  • Follows Java naming conventions and best practices

📈 Future Enhancements

Potential improvements could include:

  • GUI interface using Swing or JavaFX
  • More quiz categories and questions
  • Save/load user preferences
  • Multi-language support
  • Advanced conversation features

📧 Contact

📄 License

This project is open source and available under the MIT License.


⭐ If you find this project helpful, please give it a star to show your support!

🏷️ Tags

java chatbot beginner-friendly educational console-application programming-tutorial algorithm interactive

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors