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:

  1. Why is constructor validation important?
  2. Why did we avoid public setters?
  3. Why separate StudentPrinter?
  4. What happens if fields were public?
  5. What design improvements would you suggest?

๐Ÿ“Œ Submission Process

  1. Create feature branch:

    week-1-assignment
    
  2. Commit properly:

    feat: implement student management system phase 1
    
  3. Create Pull Request.
  4. 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


This site uses Just the Docs, a documentation theme for Jekyll.