Week 1 โ Assignment
Mini Project: Console-Based Student Management System (Phase 1)
๐ฏ Objective
Build a simple console-based Student Management System using pure Java (no collections yet).
This assignment focuses on:
- OOP fundamentals
- Encapsulation
- Constructor validation
- Clean code structure
- Defensive programming
- Separation of responsibility
This project will evolve in future weeks.
๐ Project Requirements
You must implement the following classes:
1๏ธโฃ Student Class
Fields (All Must Be Private)
- studentId (String)
- name (String)
- age (int)
- email (String)
Constructor Requirements
Constructor must:
- Validate studentId is not null or empty
- Validate name is not null or empty
- Validate age is >= 16
- Validate email contains โ@โ
If invalid โ throw IllegalArgumentException
Example:
Age must be at least 16
Invalid email format
Methods
- Getters for all fields
boolean isAdult()โ returns true if age >= 18- Override
toString()to print student details properly
Example output:
Student{id='S101', name='Riya', age=22, email='riya@email.com'}
2๏ธโฃ StudentPrinter Class
Create a separate class:
StudentPrinter
It must:
- Have method
printStudent(Student student) - Print student details
Why separate class?
Because:
Model class should not handle printing logic.
This introduces separation of concerns.
3๏ธโฃ Main Class
Create a Main class with main() method.
In main():
Step 1 โ Create 3 Valid Students
Example:
S101 โ Riya โ 22 โ riya@email.com
S102 โ Aman โ 17 โ aman@email.com
S103 โ Kavya โ 19 โ kavya@email.com
Step 2 โ Print All Students
Use StudentPrinter.
Step 3 โ Test Validation
Try creating:
- Student with age < 16
- Student with invalid email
- Student with empty name
Wrap in try-catch and print error messages.
๐ฆ Package Structure
Use proper package structure:
com.learnjava.week1.model
com.learnjava.week1.service
com.learnjava.week1
Example:
- Student โ model
- StudentPrinter โ service
- Main โ root package
๐ง Engineering Constraints
You MUST:
โ Use private fields โ Use constructor validation โ Avoid public setters (unless justified) โ Follow naming conventions โ Keep methods short โ One class per file โ No static abuse โ Proper indentation
โ What You Must NOT Do
๐ซ Do not make fields public ๐ซ Do not skip validation ๐ซ Do not write everything inside main() ๐ซ Do not use collections yet ๐ซ Do not hardcode print logic inside Student
๐ก Defensive Programming Expectations
You should handle:
- Null inputs
- Empty strings
- Invalid age
- Invalid email
- Object misuse attempts
Ask yourself:
Can someone create an invalid student?
If yes โ fix design.
๐งช Manual Testing Requirements
Test the following scenarios:
| Test Case | Expected Result |
|---|---|
| Valid student | Object created |
| Age < 16 | Exception |
| Null name | Exception |
| Invalid email | Exception |
Write test results in comments.
๐ Evaluation Criteria
| Category | Marks |
|---|---|
| Encapsulation | /10 |
| Constructor Validation | /10 |
| Clean Code | /10 |
| Separation of Responsibility | /10 |
| Defensive Programming | /10 |
Total: /50
๐ฑ Future Evolution (Do Not Implement Yet)
This system will later:
- Use Collections (Week 2)
- Persist to file (Week 3)
- Convert to REST API (Week 5)
- Connect to database (Week 6)
- Add unit tests (Week 7)
- Dockerize (Week 8)
So design carefully.
๐ง Reflection Questions (Submit with PR)
Answer in a separate file reflection.md:
- Why is constructor validation important?
- Why did we avoid public setters?
- Why separate StudentPrinter?
- What happens if fields were public?
- What design improvements would you suggest?
๐ Submission Process
-
Create feature branch:
week-1-assignment -
Commit properly:
feat: implement student management system phase 1 - Create Pull Request.
- Add reflection answers.
๐ End of Week Outcome
After completing this assignment, you should:
- Build structured Java classes
- Protect object state
- Validate inputs properly
- Understand separation of concerns
- Think defensively
- Follow clean coding standards