KA
KanugantiHaripriya/KanugantiHaripriya-pentaGon-sms-java-project2
his Java-based School Management System demonstrates core OOP concepts like inheritance, encapsulation, upcasting, and downcasting. It models real-world roles such as Staff, Teacher, and Principal with shared and specific behaviors. Static variables, methods, and blocks are used to manage common resources like the school name.
๐ซ School Management System โ Java Project-2
๐ Objective
This project demonstrates core Object-Oriented Programming (OOP) principles using Java, including:
- Inheritance: Building a class hierarchy of school staff.
- Encapsulation: Securing class attributes using access modifiers.
- Polymorphism: Achieved via upcasting and downcasting.
- Static Concepts: Usage of static variables, methods, and static blocks for shared resources.
โ Functional Requirements
1. ๐ Staff Class (Base Class)
-
Attributes (private):
String nameint ageString employeeId
-
Static Attribute:
String schoolNameโ shared by all staff members
-
Methods:
String work()โ returns a string stating the staff is working.String details()โ returns staff details.
-
Static Methods:
void showSchoolName()โ prints the school name.
-
Static Block:
- Initializes the
schoolNamewhen the class is loaded.
- Initializes the
2. ๐ฉโ๐ซ Teacher Class (Inherits from Staff)
-
Additional Attribute:
String subject
-
Methods:
void setSubject(String subject)โ sets the teacher's subject.String teach()โ returns a message that the teacher is teaching the subject.String details()โ overrides parent method to include the subject info.
3. ๐จโ๐ผ Principal Class (Inherits from Staff)
-
Additional Attribute:
int yearsOfExperience
-
Methods:
void setExperience(int experience)โ sets the principal's experience.String lead()โ returns a message indicating leadership.String details()โ overrides parent method to include experience.
4. ๐งช Main Class (Demonstration)
Demonstrates the following concepts:
- ๐ Encapsulation โ access and modify attributes via getter/setter methods.
- ๐ Upcasting โ treat
Teacher/Principalobjects asStaffreferences to call shared methods. - ๐ Downcasting โ revert
Staffreference to specific subclass to call unique methods. - ๐งท Static Variable/Method โ shared
schoolNameis displayed using a static method. - โก Static Block โ initializes static data when class is loaded.
๐ Concepts Covered
| Feature | Description |
|---|---|
| Inheritance | Teacher and Principal extend Staff |
| Encapsulation | Private attributes with public setters/getters |
| Upcasting | Staff s = new Teacher() |
| Downcasting | Teacher t = (Teacher) s |
| Static Methods/Vars | Shared school name using static members |
| Static Block | One-time initialization of static fields |
๐๏ธ Project Structure
SchoolManagementSystem/
โ
โโโ .classpath
โโโ .gitignore
โโโ .project
โโโ .settings/
โ โโโ org.eclipse.core.resources.prefs
โ โโโ org.eclipse.jdt.core.prefs
โ
โโโ src/
โ โโโ com/pentagon/smsp/
โ โโโ Staff.java
โ โโโ Teacher.java
โ โโโ Principal.java
โ โโโ SMS.java <-- Main class
โ
โโโ module-info.java
๐ป Sample Output
School Name is : Govt School
Priya teacher is teaching
name : Priya age 25 employeeId: emp01 subject: Maths
name : hari age 45 employeeId: emp05 years of experience:20 is leading the school with 20 of Experience
name : hari age 45 employeeId: emp05 years of experience:20๐ ๏ธ Technologies Used
- Java (OOP Concepts)
- Eclipse IDE (or any preferred Java IDE)