A console-based quiz game built in Java that fetches trivia questions from the Open Trivia Database API and provides an interactive quiz experience.
- Dynamic Questions: Fetches 5 random multiple-choice trivia questions from the Open Trivia Database
- Interactive Console Interface: User-friendly command-line interface with emojis and clear formatting
- Real-time Scoring: Tracks and displays your score as you progress through the quiz
- HTML Decoding: Properly handles HTML entities in questions and answers
- Immediate Feedback: Shows correct answers when you get a question wrong
Java_QuizGame_Project/
├── src/
│ ├── QuizGame.java # Main class with game logic and user interface
│ ├── Question.java # Question model class
│ ├── QuizService.java # Service class for API calls and data processing
│ └── *.class # Compiled Java bytecode files
├── lib/
│ └── json-simple-1.1.1.java.jar # JSON parsing library
├── run.bat # Windows batch script to compile and run the game
└── README.md # This file
- Java Development Kit (JDK) 8 or higher
- Internet Connection (required to fetch questions from the API)
- Windows OS (for the provided batch script)
- Double-click
run.bator run it from the command prompt:run.bat
-
Compile the Java files:
javac -cp ".;lib/json-simple-1.1.1.java.jar" src\*.java
-
Run the game:
java -cp ".;lib/json-simple-1.1.1.java.jar;src" QuizGame
- Start the Game: Run the application using one of the methods above
- Answer Questions: For each question, you'll see:
- The question text
- Four multiple-choice options (numbered 1-4)
- A prompt to enter your answer
- Enter Your Choice: Type the number (1-4) corresponding to your answer
- Get Feedback: The game will immediately tell you if you're correct or wrong
- View Final Score: After all 5 questions, see your total score
Q1: What is the capital of France?
1. London
2. Berlin
3. Paris
4. Madrid
Your answer (1-4): 3
✅ Correct!
Q2: Which planet is known as the Red Planet?
1. Venus
2. Mars
3. Jupiter
4. Saturn
Your answer (1-4): 1
❌ Wrong! Correct: Mars
🎉 Game Over! Your Score: 4/5
QuizGame: Main class containing the game loop and user interface logicQuestion: Model class representing a quiz question with options and correct answerQuizService: Service class that handles API communication and data processing
- JSON Simple 1.1.1: Used for parsing JSON responses from the Open Trivia Database API
- Open Trivia Database API: Provides the trivia questions (https://opentdb.com/)
The game fetches questions from: https://opentdb.com/api.php?amount=5&type=multiple
This endpoint returns 5 multiple-choice trivia questions in JSON format.
- "Class not found" error: Make sure you're running the java command from the project root directory
- Compilation errors: Ensure the JSON Simple JAR file is in the
lib/directory - Network errors: Check your internet connection as the game requires API access
- Input errors: Make sure to enter numbers 1-4 when answering questions
- Java 8+ installed and configured in PATH
- At least 50MB of available memory
- Active internet connection
Potential improvements for the game:
- Add difficulty level selection
- Implement different question categories
- Add a timer for each question
- Save high scores to a file
- Create a GUI version
- Add multiplayer support
- Implement question caching for offline play
Feel free to fork this project and submit pull requests for any improvements!
This project is open source and available under the MIT License.
Enjoy the quiz! 🎉