Java · Claude API · Console App

AI QUIZGENERATOR

A Java console app powered by Claude (Anthropic) that generates multiple-choice quizzes on any topic — in seconds.

0External Libs
0+Topics Tested
~0Lines of Code
Questions Possible
◈ VIEW SOURCE LIVE DEMO ↓
scroll
// system architecture
How It Works
01 / INPUT
🎯

Topic + Count

User enters any topic and picks 1–10 questions from the console.

02 / PROMPT
⚙️

Engineering

Structured prompt with strict format rules sent to Claude via HTTP POST.

03 / AI
🧠

Generation

Claude generates contextually accurate MCQs with four options and answers.

04 / PARSE
🔍

Custom Parser

Zero-dependency line parser extracts questions, options and answer indices.

05 / PLAY
🏁

Quiz + Score

Live feedback per answer, then a final score with a performance rating.

// sample output
Terminal Demo
~/AIQuizGenerator $ java -cp out com.quizgen.QuizGenerator
╔══════════════════════════════════════╗
║ 🤖 AI Quiz Generator v1.0 ║
║ Powered by Claude (Anthropic) ║
╚══════════════════════════════════════╝

Enter a topic: Java OOP
How many questions? (1-10): 3

⏳ Generating quiz on "Java OOP" via Claude...

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Question 1 of 3
❓ Which keyword is used to inherit a class in Java?
   A) implements   B) extends
   C) inherits    D) super

Your answer: B
✅ Correct!

Question 2 of 3
❓ What does 'final' do when applied to a method?
   A) Makes it static   B) Makes it abstract
   C) Prevents overriding  D) Prevents overloading

Your answer: A
❌ Wrong! → Correct answer: C) Prevents overriding

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🏁 QUIZ COMPLETE!
   Score: 2 / 3
   Result: 66.7% — 👍 Good job! Keep learning.
// dependencies
Tech Stack

JAVA 11+

Core language with modern HttpClient, clean OOP with inner model classes.

🤖

CLAUDE API

Anthropic's claude-sonnet-4 via REST — structured prompt engineering for reliable output.

🌐

java.net.http

Zero external dependencies — pure Java HTTP POST with handcrafted JSON serialization.

🔧

CUSTOM PARSER

Regex + line parsing extracts structured quiz data from Claude's raw text output.

// source highlight
Core Logic
📄 QuizGenerator.javaJAVA
// Prompt engineered for strict MCQ output format private String buildPrompt(String topic, int numQ) { return "Generate exactly " + numQ + " MCQs about \"" + topic + "\".\n" + "Format: Q1. <text>\nA)..B)..C)..D)..\nANSWER: <A-D>"; } // Zero-dependency HTTP call to Claude API HttpRequest req = HttpRequest.newBuilder() .uri(URI.create(API_URL)) .header("x-api-key", API_KEY) .header("anthropic-version", "2023-06-01") .POST(BodyPublishers.ofString(body)).build(); // Parse Claude's response into Question objects for (String line : raw.split("\n")) { if (line.matches("Q\\d+\\..*")) current = new Question(line); else if (line.startsWith("ANSWER:")) current.correctIndex = "ABCD".indexOf(line.charAt(8)); }
// developer
About Me
KH

KISHORE HARSHVARDHAN

B.Tech CSE · ITER, SOA University

Passionate about Java, DSA, and building AI-integrated applications from scratch. Open to internships, collaborations, and cool projects.