What is File Handling?
Practice Assignment: Design a Student Management System
Practice Object-Oriented Programming by designing a complete Student Management System using classes, objects, properties, methods, constructors, encapsulation, inheritance, composition, interfaces, abstraction, and polymorphism.
Assignment Introduction
This practice assignment is designed to help you apply the Object-Oriented Programming concepts learned in this chapter. Until now, you have studied important OOP topics such as class, object, properties, methods, constructor, encapsulation, inheritance, polymorphism, abstraction, interface, and composition.
Now it is time to use these concepts in a practical project-based assignment. In this assignment, you will design a Student Management System. This system will manage student details, course information, address details, marks, grades, reports, and notifications.
The goal of this assignment is not only to write code, but also to learn how to think like a software designer. You should first identify the classes, their properties, their methods, and the relationships between them. After that, you can create a simple implementation using any object-oriented programming language such as Java, C#, Python, JavaScript, PHP, or C++.
Assignment Objective
The main objective of this assignment is to design a basic Student Management System using Object-Oriented Programming principles. Students should be able to understand how real-world entities can be converted into classes and objects.
Learning Objectives
- Identify classes from a real-world problem statement.
- Create objects from classes.
- Define meaningful properties and methods for each class.
- Use constructors to initialize objects.
- Apply encapsulation to protect sensitive data.
- Use inheritance for common properties and behavior.
- Use composition for has-a relationships.
- Use abstraction to hide internal complexity.
- Use interfaces to define common contracts.
- Use polymorphism to allow different objects to behave differently through the same method.
- Design clean and maintainable object-oriented code.
Prerequisites
Before attempting this assignment, students should have a basic understanding of the following concepts. These prerequisites will help students complete the assignment smoothly.
| Prerequisite Topic | Why It Is Needed |
|---|---|
| Basic Programming Syntax | To write classes, variables, methods, and control statements. |
| Variables and Data Types | To store student name, roll number, marks, course, and other details. |
| Conditional Statements | To calculate grades and check pass or fail status. |
| Functions / Methods | To create reusable behaviors such as calculateGrade() and displayDetails(). |
| Classes and Objects | To design Student, Course, Address, Result, and Report classes. |
| Constructors | To initialize objects with required values. |
| Encapsulation | To protect data such as marks and student ID. |
| Inheritance | To reuse common details from a parent class such as Person. |
| Composition | To represent relationships such as Student has Address and Student has Course. |
Problem Statement
Design a simple Student Management System using Object-Oriented Programming. The system should store and manage student details, course details, address information, marks, grade calculation, and report generation.
Your task is to identify the required classes, define their properties and methods, apply OOP principles, and create a simple working model of the system.
Functional Requirements
Functional requirements describe what the system should do. Your Student Management System should support the following features:
Required Features
- Add student personal details such as name, age, contact number, and roll number.
- Store student address details such as city, state, country, and postal code.
- Store course details such as course name, course code, and duration.
- Store marks for a student.
- Validate marks so that marks cannot be less than 0 or greater than 100.
- Calculate grade based on marks.
- Check whether the student has passed or failed.
- Display complete student profile.
- Generate a student marks report.
- Generate different types of reports using a common report interface.
- Send a simple notification message after report generation.
Non-Functional Requirements
Non-functional requirements describe how the system should be designed. Your solution should follow clean OOP design principles.
Design Requirements
- The code should be easy to read and understand.
- Each class should have one clear responsibility.
- Class names should be meaningful.
- Method names should clearly describe actions.
- Important data should be protected using encapsulation.
- Constructor should be used to initialize required values.
- Inheritance should be used only where there is an is-a relationship.
- Composition should be used where there is a has-a relationship.
- Interfaces should be used for common behaviors.
- The system should be easy to extend in the future.
Step 1: Identify Classes
The first step in designing this project is identifying the possible classes. In OOP, classes usually come from important nouns in the problem statement.
From the problem statement, we can identify the following possible classes:
| Class Name | Reason for Class | Responsibility |
|---|---|---|
| Person | Student and Teacher can share common personal details. | Stores common details such as name, age, and contact number. |
| Student | Student is the main entity of the system. | Stores student-specific details and displays student profile. |
| Address | Student has address details. | Stores city, state, country, and postal code. |
| Course | Student is enrolled in a course. | Stores course name, course code, and duration. |
| Result | Student has marks and grade. | Stores marks, calculates grade, and checks pass/fail status. |
| ReportGenerator | Different reports may be generated. | Defines common report generation behavior. |
| MarksReport | One type of report is marks report. | Generates student marks report. |
| NotificationService | System may send notification messages. | Sends simple notification to users. |
Step 2: Identify Properties / Attributes
After identifying classes, we should define what data each class will store. These data items become properties or attributes.
| Class | Suggested Properties / Attributes |
|---|---|
| Person | name, age, contactNumber |
| Student | studentId, rollNumber, address, course, result |
| Address | city, state, country, postalCode |
| Course | courseCode, courseName, durationInMonths |
| Result | marks |
| MarksReport | student |
| NotificationService | message |
Step 3: Identify Methods
Methods represent the actions or behavior of an object. Look for verbs in the requirement to identify possible methods.
| Class | Suggested Methods | Purpose |
|---|---|---|
| Person | displayBasicDetails() | Displays common personal details. |
| Student | displayStudentProfile() | Displays complete student details. |
| Address | displayAddress() | Displays address information. |
| Course | displayCourseDetails() | Displays course information. |
| Result | setMarks(), getMarks(), calculateGrade(), isPassed(), displayResult() | Manages marks, grade, and pass/fail logic. |
| ReportGenerator | generateReport() | Defines common report generation behavior. |
| MarksReport | generateReport() | Generates marks report. |
| NotificationService | sendNotification() | Sends notification message. |
Step 4: Identify OOP Relationships
A good OOP design requires identifying relationships between classes. This helps us decide where to use inheritance, composition, interface, and polymorphism.
| Relationship | OOP Concept | Explanation |
|---|---|---|
| Student is a Person | Inheritance | Student can inherit name, age, and contact number from Person. |
| Student has an Address | Composition | Student contains an Address object. |
| Student has a Course | Composition | Student contains a Course object. |
| Student has a Result | Composition | Student contains a Result object. |
| Marks should not be directly changed without validation | Encapsulation | Marks should be private and updated through setMarks(). |
| Different reports can use same method name | Interface and Polymorphism | ReportGenerator interface can define generateReport(). |
| Report generation hides internal steps | Abstraction | User calls generateReport() without knowing internal logic. |
Suggested Class Design
The following design shows how classes can be connected in this assignment.
// Suggested class relationship overview
Person
|
|-- Student
Student has Address
Student has Course
Student has Result
ReportGenerator interface
|
|-- MarksReport
NotificationService sends notification
Assignment Task 1: Create the Person Class
Create a Person class to store common personal details. This class will act as a parent class for Student.
Requirements
- Create properties: name, age, contactNumber.
- Create a constructor to initialize these values.
- Create a method displayBasicDetails().
- Use protected access if the child class needs access to these values.
class Person {
protected String name;
protected int age;
protected String contactNumber;
Person(String personName, int personAge, String contact) {
name = personName;
age = personAge;
contactNumber = contact;
}
void displayBasicDetails() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Contact Number: " + contactNumber);
}
}
Assignment Task 2: Create the Address Class
Create an Address class to store address details. This class will be used inside the Student class through composition.
Requirements
- Create properties: city, state, country, postalCode.
- Create a constructor to initialize address details.
- Create a method displayAddress().
- Keep properties private to apply encapsulation.
class Address {
private String city;
private String state;
private String country;
private String postalCode;
Address(String studentCity, String studentState, String studentCountry, String studentPostalCode) {
city = studentCity;
state = studentState;
country = studentCountry;
postalCode = studentPostalCode;
}
void displayAddress() {
System.out.println("City: " + city);
System.out.println("State: " + state);
System.out.println("Country: " + country);
System.out.println("Postal Code: " + postalCode);
}
}
Assignment Task 3: Create the Course Class
Create a Course class to store course information. A student should have one course object.
Requirements
- Create properties: courseCode, courseName, durationInMonths.
- Create a constructor to initialize course details.
- Create a method displayCourseDetails().
class Course {
private String courseCode;
private String courseName;
private int durationInMonths;
Course(String code, String name, int duration) {
courseCode = code;
courseName = name;
durationInMonths = duration;
}
void displayCourseDetails() {
System.out.println("Course Code: " + courseCode);
System.out.println("Course Name: " + courseName);
System.out.println("Duration: " + durationInMonths + " months");
}
}
Assignment Task 4: Create the Result Class
Create a Result class to store marks and calculate grade. This class should properly apply encapsulation because marks should not be stored with invalid values.
Requirements
- Create a private property marks.
- Create setMarks() method to validate marks.
- Create getMarks() method to return marks.
- Create calculateGrade() method.
- Create isPassed() method.
- Create displayResult() method.
- Marks should be between 0 and 100.
class Result {
private int marks;
Result(int studentMarks) {
setMarks(studentMarks);
}
void setMarks(int studentMarks) {
if (studentMarks >= 0 && studentMarks <= 100) {
marks = studentMarks;
} else {
marks = 0;
System.out.println("Invalid marks. Marks must be between 0 and 100.");
}
}
int getMarks() {
return marks;
}
String calculateGrade() {
if (marks >= 90) {
return "A";
} else if (marks >= 75) {
return "B";
} else if (marks >= 60) {
return "C";
} else if (marks >= 40) {
return "D";
} else {
return "Fail";
}
}
boolean isPassed() {
return marks >= 40;
}
void displayResult() {
System.out.println("Marks: " + marks);
System.out.println("Grade: " + calculateGrade());
System.out.println("Status: " + (isPassed() ? "Passed" : "Failed"));
}
}
Assignment Task 5: Create the Student Class
Create a Student class that inherits from Person and uses Address, Course, and Result objects through composition.
Requirements
- Student should extend Person.
- Create properties: studentId and rollNumber.
- Add Address, Course, and Result objects as properties.
- Create a constructor to initialize all required values.
- Create displayStudentProfile() method.
- Use composition for Address, Course, and Result.
class Student extends Person {
private String studentId;
private int rollNumber;
private Address address;
private Course course;
private Result result;
Student(String id, String studentName, int studentAge, String contact, int roll, Address studentAddress, Course studentCourse, Result studentResult) {
super(studentName, studentAge, contact);
studentId = id;
rollNumber = roll;
address = studentAddress;
course = studentCourse;
result = studentResult;
}
void displayStudentProfile() {
System.out.println("Student ID: " + studentId);
displayBasicDetails();
System.out.println("Roll Number: " + rollNumber);
System.out.println("--- Address Details ---");
address.displayAddress();
System.out.println("--- Course Details ---");
course.displayCourseDetails();
System.out.println("--- Result Details ---");
result.displayResult();
}
Result getResult() {
return result;
}
String getStudentName() {
return name;
}
}
Assignment Task 6: Create a ReportGenerator Interface
Create an interface called ReportGenerator. This interface should define a common method named generateReport().
Requirements
- Create an interface named ReportGenerator.
- Declare a method generateReport().
- Create a MarksReport class that implements ReportGenerator.
- Use polymorphism to call generateReport().
interface ReportGenerator {
void generateReport();
}
class MarksReport implements ReportGenerator {
private Student student;
MarksReport(Student reportStudent) {
student = reportStudent;
}
public void generateReport() {
System.out.println("===== Student Marks Report =====");
System.out.println("Student Name: " + student.getStudentName());
System.out.println("Marks: " + student.getResult().getMarks());
System.out.println("Grade: " + student.getResult().calculateGrade());
System.out.println("Status: " + (student.getResult().isPassed() ? "Passed" : "Failed"));
}
}
Assignment Task 7: Create NotificationService Class
Create a NotificationService class to send simple notification messages. This class demonstrates separation of responsibility.
Requirements
- Create a method sendNotification().
- The method should accept a message.
- The method should display the notification message.
class NotificationService {
void sendNotification(String message) {
System.out.println("Notification: " + message);
}
}
Complete Assignment Sample Solution in Java
The following sample solution combines all classes and demonstrates a basic working Student Management System. Students can use this as a reference after trying the assignment themselves.
class Person {
protected String name;
protected int age;
protected String contactNumber;
Person(String personName, int personAge, String contact) {
name = personName;
age = personAge;
contactNumber = contact;
}
void displayBasicDetails() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Contact Number: " + contactNumber);
}
}
class Address {
private String city;
private String state;
private String country;
private String postalCode;
Address(String studentCity, String studentState, String studentCountry, String studentPostalCode) {
city = studentCity;
state = studentState;
country = studentCountry;
postalCode = studentPostalCode;
}
void displayAddress() {
System.out.println("City: " + city);
System.out.println("State: " + state);
System.out.println("Country: " + country);
System.out.println("Postal Code: " + postalCode);
}
}
class Course {
private String courseCode;
private String courseName;
private int durationInMonths;
Course(String code, String name, int duration) {
courseCode = code;
courseName = name;
durationInMonths = duration;
}
void displayCourseDetails() {
System.out.println("Course Code: " + courseCode);
System.out.println("Course Name: " + courseName);
System.out.println("Duration: " + durationInMonths + " months");
}
}
class Result {
private int marks;
Result(int studentMarks) {
setMarks(studentMarks);
}
void setMarks(int studentMarks) {
if (studentMarks >= 0 && studentMarks <= 100) {
marks = studentMarks;
} else {
marks = 0;
System.out.println("Invalid marks. Marks must be between 0 and 100.");
}
}
int getMarks() {
return marks;
}
String calculateGrade() {
if (marks >= 90) {
return "A";
} else if (marks >= 75) {
return "B";
} else if (marks >= 60) {
return "C";
} else if (marks >= 40) {
return "D";
} else {
return "Fail";
}
}
boolean isPassed() {
return marks >= 40;
}
void displayResult() {
System.out.println("Marks: " + marks);
System.out.println("Grade: " + calculateGrade());
System.out.println("Status: " + (isPassed() ? "Passed" : "Failed"));
}
}
class Student extends Person {
private String studentId;
private int rollNumber;
private Address address;
private Course course;
private Result result;
Student(String id, String studentName, int studentAge, String contact, int roll, Address studentAddress, Course studentCourse, Result studentResult) {
super(studentName, studentAge, contact);
studentId = id;
rollNumber = roll;
address = studentAddress;
course = studentCourse;
result = studentResult;
}
void displayStudentProfile() {
System.out.println("===== Student Profile =====");
System.out.println("Student ID: " + studentId);
displayBasicDetails();
System.out.println("Roll Number: " + rollNumber);
System.out.println("--- Address Details ---");
address.displayAddress();
System.out.println("--- Course Details ---");
course.displayCourseDetails();
System.out.println("--- Result Details ---");
result.displayResult();
}
Result getResult() {
return result;
}
String getStudentName() {
return name;
}
}
interface ReportGenerator {
void generateReport();
}
class MarksReport implements ReportGenerator {
private Student student;
MarksReport(Student reportStudent) {
student = reportStudent;
}
public void generateReport() {
System.out.println("===== Student Marks Report =====");
System.out.println("Student Name: " + student.getStudentName());
System.out.println("Marks: " + student.getResult().getMarks());
System.out.println("Grade: " + student.getResult().calculateGrade());
System.out.println("Status: " + (student.getResult().isPassed() ? "Passed" : "Failed"));
}
}
class NotificationService {
void sendNotification(String message) {
System.out.println("Notification: " + message);
}
}
public class Main {
public static void main(String[] args) {
Address address1 = new Address("Kolkata", "West Bengal", "India", "700001");
Course course1 = new Course("PL101", "Programming Fundamentals", 6);
Result result1 = new Result(85);
Student student1 = new Student("S101", "Rahul", 20, "9876543210", 101, address1, course1, result1);
student1.displayStudentProfile();
ReportGenerator report = new MarksReport(student1);
report.generateReport();
NotificationService notificationService = new NotificationService();
notificationService.sendNotification("Marks report generated successfully for " + student1.getStudentName());
}
}
Expected Output
The exact output may vary depending on formatting, but the output should look similar to this:
===== Student Profile =====
Student ID: S101
Name: Rahul
Age: 20
Contact Number: 9876543210
Roll Number: 101
--- Address Details ---
City: Kolkata
State: West Bengal
Country: India
Postal Code: 700001
--- Course Details ---
Course Code: PL101
Course Name: Programming Fundamentals
Duration: 6 months
--- Result Details ---
Marks: 85
Grade: B
Status: Passed
===== Student Marks Report =====
Student Name: Rahul
Marks: 85
Grade: B
Status: Passed
Notification: Marks report generated successfully for Rahul
OOP Concepts Applied in This Assignment
The following table explains how different OOP concepts are used in this assignment.
| OOP Concept | Where It Is Used | Explanation |
|---|---|---|
| Class | Person, Student, Address, Course, Result | Each class represents a real-world or logical entity. |
| Object | student1, address1, course1, result1 | Objects are actual instances created from classes. |
| Properties | name, age, marks, courseName, city | Properties store object data. |
| Methods | displayStudentProfile(), calculateGrade(), generateReport() | Methods define object behavior. |
| Constructor | Person(), Student(), Address(), Course(), Result() | Constructors initialize object values. |
| Encapsulation | private marks in Result | Marks are protected and validated before storing. |
| Inheritance | Student extends Person | Student reuses common details from Person. |
| Composition | Student has Address, Course, and Result | Student is built using other objects. |
| Interface | ReportGenerator | Defines a contract for report generation. |
| Polymorphism | ReportGenerator report = new MarksReport() | Interface reference points to implementing class object. |
| Abstraction | generateReport() | User calls report generation without knowing internal details. |
Assignment Questions for Students
Students should answer the following questions after completing the assignment. These questions help test conceptual understanding.
Conceptual Questions
- Which classes did you create in the Student Management System?
- Which class is used as the parent class?
- Why does Student inherit from Person?
- Which classes are used through composition?
- Why is Address better as a separate class instead of storing all address fields directly in Student?
- Where is encapsulation used in this assignment?
- Why should marks be private?
- What is the purpose of the ReportGenerator interface?
- How does polymorphism appear in the report generation part?
- How can this project be extended in the future?
Extension Tasks
After completing the basic assignment, students can improve the project by adding more features. These extension tasks are optional but highly recommended.
Optional Enhancements
- Add a Teacher class that also extends Person.
- Add Attendance class to store total classes and attended classes.
- Add AttendanceReport class that implements ReportGenerator.
- Add Fee class to store total fee, paid fee, and due fee.
- Add FeeReport class that implements ReportGenerator.
- Add multiple students using an array or list.
- Add search student by roll number.
- Add update student marks feature.
- Add validation for contact number and postal code.
- Add menu-based program using console input.
Evaluation Criteria
The assignment can be evaluated using the following criteria.
| Criteria | Marks | What to Check |
|---|---|---|
| Class Identification | 10 | Correct classes are created for real-world entities. |
| Properties and Methods | 15 | Classes have meaningful attributes and behaviors. |
| Constructor Usage | 10 | Objects are initialized properly using constructors. |
| Encapsulation | 15 | Private data and validation are used correctly. |
| Inheritance | 10 | Student correctly inherits from Person. |
| Composition | 15 | Student correctly contains Address, Course, and Result objects. |
| Interface and Polymorphism | 15 | ReportGenerator interface and MarksReport implementation are used properly. |
| Code Readability | 10 | Code is clean, readable, and properly named. |
| Total | 100 | Complete OOP-based Student Management System design. |
Common Mistakes to Avoid
Students should avoid the following mistakes while completing this assignment.
Mistakes
- Putting all code inside one class.
- Making all properties public.
- Not validating marks before storing.
- Using inheritance where composition is better.
- Not using constructors properly.
- Using unclear class names or method names.
- Not separating responsibilities between classes.
- Creating interface but not using it properly.
Correct Approach
- Create separate classes for separate responsibilities.
- Use private properties where needed.
- Use setter methods for validation.
- Use inheritance only for is-a relationships.
- Use composition for has-a relationships.
- Use meaningful names for classes and methods.
- Use constructors to initialize objects.
- Use interfaces for common behavior.
Best Practices for This Assignment
Follow these best practices to write a clean and professional solution.
Recommended Practices
- Read the problem statement before writing code.
- Draw a small class diagram first.
- Write one class at a time and test it.
- Keep properties private wherever possible.
- Use constructors for required data.
- Use methods for object behavior.
- Keep each method focused on one task.
- Use composition for Address, Course, and Result.
- Use interface for report generation.
- Use clear output formatting for readability.
- Test with valid and invalid marks.
- Write comments only where needed.
Frequently Asked Questions
1. What is the main goal of this assignment?
The main goal is to apply Object-Oriented Programming concepts by designing a Student Management System using classes, objects, properties, methods, constructors, encapsulation, inheritance, composition, interface, abstraction, and polymorphism.
2. Which class should be the parent class?
The Person class can be used as the parent class because common personal details such as name, age, and contact number can be reused by Student and other future classes such as Teacher.
3. Why should Student have Address instead of inheriting Address?
Because Student is not an Address. A Student has an Address. Therefore, composition is the correct relationship.
4. Where is encapsulation used?
Encapsulation is used in the Result class by keeping marks private and updating marks through setMarks() with validation.
5. Where is inheritance used?
Inheritance is used when Student extends Person. This represents an is-a relationship because a student is a person.
6. Where is composition used?
Composition is used when Student contains Address, Course, and Result objects. This represents has-a relationships.
7. Why is ReportGenerator an interface?
ReportGenerator defines a common contract for generating reports. Different report classes can implement this interface and generate different types of reports.
8. How is polymorphism used?
Polymorphism is used when a ReportGenerator reference points to a MarksReport object and calls generateReport(). In the future, the same interface can be used for AttendanceReport or FeeReport.
9. Can this assignment be done in languages other than Java?
Yes. The same design can be implemented in any object-oriented programming language such as C#, Python, JavaScript, PHP, C++, Kotlin, or Swift. The syntax will change, but the OOP design remains the same.
10. What should students submit?
Students should submit class design, source code, sample output, and a short explanation of where each OOP concept is used.
Assignment Summary
This assignment helps students practice Object-Oriented Programming using a practical Student Management System. Students must identify classes, define properties and methods, use constructors, and apply important OOP concepts in a meaningful way.
The assignment demonstrates inheritance through Student and Person, composition through Student with Address, Course, and Result, encapsulation through private marks, abstraction through report generation, interface through ReportGenerator, and polymorphism through report implementation.
By completing this assignment, students will understand how OOP concepts work together in real-world application design. This assignment also prepares students for larger projects such as Library Management System, Banking System, E-Commerce System, and Hospital Management System.
Key Takeaway
The Student Management System assignment is a practical way to apply OOP concepts. It teaches students how to convert real-world requirements into classes, objects, properties, methods, and meaningful relationships such as inheritance, composition, encapsulation, interface, and polymorphism.