Master Java fundamentals through 47 real-world, story-based challenges. Each exercise puts you in a practical scenario — cinema ticketing, ATM withdrawals, email validation, and more.
279 JUnit tests across 10 topics
Edit the Java files on your machine and run tests with Maven. Only edit files under src/main/java/ — never change the test files.
- Prerequisites
- Setup guide
- How to run tests
- Topics covered
- Suggested learning order
- Project structure
- How to solve a challenge
- Troubleshooting
- Progress checklist
Everything you need before opening the project.
| Requirement | Minimum version | Why you need it |
|---|---|---|
| Java JDK | 17 or higher | Compiles and runs the lab code |
| Internet connection | — | First Maven run downloads JUnit and dependencies |
| Terminal | — | PowerShell, Command Prompt, or Mac/Linux terminal |
| Tool | Why it helps |
|---|---|
| VS Code or IntelliJ IDEA | Edit Java with syntax highlighting and one-click test runs |
| Extension Pack for Java (VS Code) | Run individual tests from the editor |
| Git | Version control for your solutions |
| Tool | Reason |
|---|---|
| Maven installed globally | This project includes mvnw / mvnw.cmd (Maven Wrapper) |
| Paid IDE license | IntelliJ Community Edition is free and works fine |
- Windows 10/11, macOS, or Linux
- ~200 MB disk space (more after first Maven build in
target/) - JDK 17+ from Adoptium or Oracle
Follow these steps once before you start solving challenges.
Windows
- Download JDK 17+ from Adoptium
- Run the installer (keep default options)
- Restart your terminal and IDE after install
macOS
brew install openjdk@17Or download from Adoptium and install the .pkg.
Linux (Ubuntu/Debian)
sudo apt update
sudo apt install openjdk-17-jdkOpen a terminal and run:
java -versionYou should see output like:
openjdk version "17.0.x" ...
Also check the compiler:
javac -versionIf either command is not found, Java is not on your PATH. Reinstall JDK or add JAVA_HOME to your environment variables.
Windows — set JAVA_HOME (if IDE cannot find Java)
- Search Environment Variables in Windows
- Add a new system/user variable:
- Name:
JAVA_HOME - Value:
C:\Program Files\Eclipse Adoptium\jdk-17.x.x-hotspot(your actual JDK path)
- Name:
- Add
%JAVA_HOME%\binto yourPathvariable - Restart terminal and IDE
If you already have the folder, skip to Step 4.
# Example — clone or copy the project folder
cd C:\coding-room
# Your project should be at:
# C:\coding-room\chaicode-java-labsVS Code
- File → Open Folder
- Select
chaicode-java-labs(the folder that containspom.xml) - Install Extension Pack for Java when prompted
- Wait for the Java language server to finish loading (status bar bottom-right)
IntelliJ IDEA
- File → Open
- Select the
chaicode-java-labsfolder - IntelliJ detects Maven automatically — click Load Maven Project if asked
Open a terminal in the project root (where pom.xml lives).
Windows (PowerShell or Command Prompt)
cd C:\coding-room\chaicode-java-labs
.\mvnw.cmd testmacOS / Linux
cd /path/to/chaicode-java-labs
chmod +x mvnw
./mvnw testWhat to expect on first run
- Maven downloads JUnit and plugins (1–3 minutes depending on network)
- You will see many failing tests — this is normal
- Your job is to implement the methods and make tests pass
Successful first run looks like:
Tests run: 279, Failures: ..., Errors: ...
BUILD SUCCESS ← build succeeded (tests may still fail until you write code)
If the build itself fails (compile errors, Maven not found), see Troubleshooting.
If you see:
.\mvnw.cmd cannot be loaded because running scripts is disabled
Run once:
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedOr use Command Prompt instead:
cd C:\coding-room\chaicode-java-labs
mvnw.cmd testYour terminal should list these files:
pom.xml
mvnw.cmd (Windows) or mvnw (Mac/Linux)
README.md
src/
Always run Maven commands from this folder, not from src/.
All commands below assume you are in the project root.
Windows: use .\mvnw.cmd
macOS / Linux: use ./mvnw
Runs every test class in the project (279 tests).
.\mvnw.cmd test./mvnw testUse this to check overall progress after completing several challenges.
Example output when done:
Tests run: 279, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
Each challenge has one test class, e.g. EmployeeBadgeTest for EmployeeBadge.java.
.\mvnw.cmd test -Dtest=EmployeeBadgeTest./mvnw test -Dtest=EmployeeBadgeTestMore examples:
.\mvnw.cmd test -Dtest=TicketPricingTest
.\mvnw.cmd test -Dtest=ShoppingCartTotalTest
.\mvnw.cmd test -Dtest=PalindromeCheckerTest
.\mvnw.cmd test -Dtest=LoanEMITestThis is the recommended way to work — solve one challenge, run its test class, then move on.
Use ClassName#methodName to run exactly one test.
.\mvnw.cmd test -Dtest=EmployeeBadgeTest#managerBadge./mvnw test -Dtest=EmployeeBadgeTest#managerBadgeMore examples:
.\mvnw.cmd test -Dtest=TicketPricingTest#childAge5Weekday
.\mvnw.cmd test -Dtest=PrimeCheckerTest#seventeenIsPrime
.\mvnw.cmd test -Dtest=RestaurantBillTest#standardBillUse this when debugging one failing case without running the whole class.
Separate class names with commas (no spaces).
.\mvnw.cmd test -Dtest=EmployeeBadgeTest,ProductListingTest,FitnessProfileTest./mvnw test -Dtest=EmployeeBadgeTest,ProductListingTest,FitnessProfileTestRun all tests in one topic (wildcard):
# All variables challenges
.\mvnw.cmd test -Dtest=com.chaicode.variables.*Test
# All conditionals challenges
.\mvnw.cmd test -Dtest=com.chaicode.conditionals.*Test
# All for-loop challenges
.\mvnw.cmd test -Dtest=com.chaicode.forloop.*TestRun multiple specific methods from the same class:
.\mvnw.cmd test -Dtest=EmployeeBadgeTest#managerBadge+staffBadge| Goal | Command (Windows) |
|---|---|
| Run all tests | .\mvnw.cmd test |
| Run one challenge | .\mvnw.cmd test -Dtest=EmployeeBadgeTest |
| Run one test case | .\mvnw.cmd test -Dtest=EmployeeBadgeTest#managerBadge |
| Run multiple challenges | .\mvnw.cmd test -Dtest=TestA,TestB,TestC |
| Run whole topic | .\mvnw.cmd test -Dtest=com.chaicode.variables.*Test |
| Compile only (no tests) | .\mvnw.cmd compile |
| Clean + full test run | .\mvnw.cmd clean test |
On Mac/Linux, replace .\mvnw.cmd with ./mvnw.
VS Code
- Open a test file, e.g.
src/test/java/com/chaicode/variables/EmployeeBadgeTest.java - Click Run Test above a
@Testmethod (single case) - Click Run Tests above the class name (whole challenge)
- Or open the Testing sidebar (flask icon) and run from there
IntelliJ IDEA
- Open a test file
- Green ▶ next to a method → run one test case
- Green ▶ next to the class name → run all tests in that class
- Right-click
src/test/java→ Run 'All Tests' for the full lab
| Topic | Package | Challenges | Concepts |
|---|---|---|---|
| Variables & Data Types | variables |
3 | int, double, boolean, String, records |
| Operators | operators |
4 | Arithmetic, comparison, logical, compound |
| Conditionals | conditionals |
12 | if/else, switch, ternary, validation |
| For Loop | forloop |
4 | Summation, factorial, primes, FizzBuzz |
| While Loop | whileloop |
4 | Digit manipulation, savings planner, ATM |
| Do-While Loop | dowhileloop |
3 | Survey input, PIN retry, order counting |
| Scanner | scanner |
3 | java.util.Scanner, parsing input |
| Methods | methods |
4 | Parameters, return types, overloading patterns |
| Arrays (1D & 2D) | arrays |
5 | Search, stats, matrices, gradebook |
| Strings & StringBuilder | strings |
5 | String methods, StringBuilder, validation |
- Variables →
EmployeeBadge.java,ProductListing.java,FitnessProfile.java - Operators →
RestaurantBill.java,SaleDiscount.java,TimeBreakdown.java,GameScoreComparer.java - Conditionals →
TicketPricing.javathroughSeasonActivity.java(12 challenges) - For Loop →
ShoppingCartTotal.java,FactorialCalculator.java,PrimeChecker.java,FizzBuzzCounter.java - While Loop →
ATMWithdrawal.java,DigitSum.java,ReverseDigits.java,SavingsPlanner.java - Do-While Loop →
SurveyAverage.java,PinValidator.java,PizzaOrders.java - Scanner →
CafeOrder.java,StudentRegistration.java,SimpleCalculator.java - Methods →
GeometryAreas.java,TemperatureConverter.java,LoanEMI.java,GreetingGenerator.java - Arrays →
ClassroomStats.java,InventorySearch.java,CinemaSeats.java,MatrixAddition.java,GradebookAverage.java - Strings →
PalindromeChecker.java,EmailValidator.java,SlugBuilder.java,TitleCase.java,CreditCardMask.java
chaicode-java-labs/
├── pom.xml
├── mvnw / mvnw.cmd
├── README.md
│
├── src/main/java/com/chaicode/
│ ├── variables/ ← YOU EDIT THESE
│ ├── operators/
│ ├── conditionals/ (12 real-world stories from ChaiCode)
│ ├── forloop/
│ ├── whileloop/
│ ├── dowhileloop/
│ ├── scanner/
│ ├── methods/
│ ├── arrays/
│ └── strings/
│
└── src/test/java/com/chaicode/
└── ... ← DO NOT EDIT (JUnit tests)
- Open a challenge file (e.g.
src/main/java/com/chaicode/variables/EmployeeBadge.java) - Read the Javadoc at the top — it explains the story, rules, and return values
- Replace
// Your code herewith your implementation - Run that challenge's tests:
.\mvnw.cmd test -Dtest=EmployeeBadgeTest- If one test fails, run just that case to debug:
.\mvnw.cmd test -Dtest=EmployeeBadgeTest#managerBadge- When all tests in the class pass, move to the next challenge
| # | Class | Test class | Story |
|---|---|---|---|
| 01 | TicketPricing |
TicketPricingTest |
Starlight Cinema ticket pricing |
| 02 | TrafficLight |
TrafficLightTest |
SafeDrive traffic light simulator |
| 03 | GradeCalculator |
GradeCalculatorTest |
Ms. Parker's report cards |
| 04 | WeatherAdvice |
WeatherAdviceTest |
TrailBuddy hiking app |
| 05 | LibraryCard |
LibraryCardTest |
Maple Town Library |
| 06 | ShippingCalculator |
ShippingCalculatorTest |
ShopSwift store shipping |
| 07 | CoffeeShop |
CoffeeShopTest |
Bean & Brew Cafe |
| 08 | TaxCalculator |
TaxCalculatorTest |
Sam's freelance taxes |
| 09 | PasswordStrength |
PasswordStrengthTest |
SecureApp signup |
| 10 | TipCalculator |
TipCalculatorTest |
TipEasy restaurant |
| 11 | ParkingFee |
ParkingFeeTest |
City Central Parking |
| 12 | SeasonActivity |
SeasonActivityTest |
WanderLust Travel |
- Install JDK 17+ from Adoptium
- Set
JAVA_HOMEand add%JAVA_HOME%\bintoPath - Restart terminal and IDE
You do not need global Maven. Always use:
.\mvnw.cmd testNot mvn test.
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedOr use Command Prompt: mvnw.cmd test
- Check internet connection
- Retry:
.\mvnw.cmd test - Corporate proxy may require Maven proxy settings
Normal before you write solutions. Implement the method in the challenge file.
Some challenges return objects (BorrowResult, StudentInfo, etc.). Your method is still returning null — finish the implementation.
- Install Extension Pack for Java
- Reload:
Ctrl+Shift+P→ Developer: Reload Window - Open the folder that contains
pom.xml
File → Invalidate Caches → Invalidate and Restart, or right-click pom.xml → Maven → Reload project
After a test run, detailed reports are in:
target\surefire-reports\
- EmployeeBadge
- ProductListing
- FitnessProfile
- RestaurantBill
- SaleDiscount
- TimeBreakdown
- GameScoreComparer
- TicketPricing … SeasonActivity (12 total)
- ShoppingCartTotal, FactorialCalculator, PrimeChecker, FizzBuzzCounter
- ATMWithdrawal, DigitSum, ReverseDigits, SavingsPlanner
- SurveyAverage, PinValidator, PizzaOrders
- CafeOrder, StudentRegistration, SimpleCalculator
- GeometryAreas, TemperatureConverter, LoanEMI, GreetingGenerator
- ClassroomStats, InventorySearch, CinemaSeats, MatrixAddition, GradebookAverage
- PalindromeChecker, EmailValidator, SlugBuilder, TitleCase, CreditCardMask
Good luck — start with EmployeeBadge.java and run .\mvnw.cmd test -Dtest=EmployeeBadgeTest!