GitHunt
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 name
    • int age
    • String 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 schoolName when the class is loaded.

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/Principal objects as Staff references to call shared methods.
  • ๐Ÿ”„ Downcasting โ€“ revert Staff reference to specific subclass to call unique methods.
  • ๐Ÿงท Static Variable/Method โ€“ shared schoolName is 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)