Requirements & Design
Define the problem, inputs and outputs, constraints, and a simple plan for a word statistics tool.
Requirements & Design is a free Java Academy lesson on CoddyKit. This is lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, and your progress syncs across the web and the CoddyKit app. The Java Academy course includes 3 lessons in total.
Project goal
Goal: Build a tiny tool that reports basic word statistics. We will tokenize text, normalize words, count frequencies, and show the top results.
Inputs and outputs
Input: a short text string, hard coded for now. Output: total words, unique words, and top N most frequent words with counts.
Normalization rules
Normalization: lowercase the text and strip punctuation. Split on non letters so tokens are clean and comparable.
Counting strategy
Counting: map each word to a frequency. In Java, a simple HashMap of String to Integer is clear and enough for a first pass.
Reporting plan
Reporting: print totals and top N such as top three words. When counts tie, any order is fine. Keep the output simple.
Prototype: tiny run
Prototype: lowercase, strip punctuation, split, count, and print top three. We hard code the text for now and keep the output readable.
public class Main {
public static void main(String[] args) {
// Prototype: hard coded text, normalize, count, and print simple stats.
String text = "To be, or not to be: that is the question. To be or not?";
// 1) Lowercase
String lower = text.toLowerCase();
// 2) Replace non letters with spaces for splitting
String cleaned = lower.replaceAll("[^a-z]+", " ");
// 3) Split on spaces and filter empty tokens
String[] tokens = cleaned.trim().split("\\s+");
java.util.Map<String, Integer> freq = new java.util.HashMap<>();
int total = 0;
for (int i = 0; i < tokens.length; i = i + 1) {
String w = tokens[i];
if (w.length() == 0) continue;
total = total + 1;
Integer c = freq.get(w);
if (c == null) freq.put(w, 1);
else freq.put(w, c + 1);
}
// Simple top 3 by repeated linear scan (fine for small texts)
for (int k = 0; k < 3; k = k + 1) {
String bestWord = null;
int bestCount = -1;
for (java.util.Map.Entry<String,Integer> e : freq.entrySet()) {
String word = e.getKey();
int count = e.getValue();
if (count > bestCount) {
bestCount = count;
bestWord = word;
}
}
if (bestWord == null) break;
System.out.println("#" + (k + 1) + " " + bestWord + " = " + bestCount);
// mark as used
freq.put(bestWord, -1000000);
}
System.out.println("Total words: " + total);
System.out.println("Unique words: " + (freq.size()));
}
}
Design first
Quick check: Which step should come earliest when designing this mini project?
Recap
Recap: We fixed scope, defined IO, set rules, picked a simple map for counting, and validated the plan with a tiny run.
Learn Java with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 104
- Lessons
- 374
Frequently Asked Questions
Is the “Requirements & Design” lesson free?
Yes — the full text of “Requirements & Design” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO. The Java Academy course includes 3 lessons in total.
What will I learn in “Requirements & Design”?
Define the problem, inputs and outputs, constraints, and a simple plan for a word statistics tool. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Java Academy?
No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.
How long does the “Requirements & Design” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Java Academy lesson?
Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Requirements & Design
- Implementation
- Testing & Extensions