Java College Management System Lab
Java College Management System Lab
Implementing multiple inheritance through interfaces allows the Java College management system to separate functionalities across different constructs. The 'Department' class inherits attributes from 'Teacher' while also implementing methods from the 'College' interface, securing both class and interface benefits. Interfaces enable the Department class to implement college-specific methods, like 'getDetails' and display functions, promoting a modular design without the complexity of class-based multiple inheritance .
The 'Developer' class calculates its salary by adding a bonus to the base salary, specifically using the formula baseSalary + bonus. In contrast, the 'Manager' class calculates its salary by adding the product of projectBonus and managedTeamSize to the base salary, according to the formula baseSalary + (projectBonus * managedTeamSize).
The 'Department' class in the Java College management system extends the abstract abilities of Java through its implementation of the 'College' interface, which contains abstract methods 'getDetails' and 'showDetails'. The class must provide concrete implementations for these methods, so it effectively uses abstraction to separate what an object can do from how it does it. Additionally, the department number setting logic encapsulates specific behavior, achieving abstraction of direct department assignment .
The 'CMS' class uses the 'Department' class to handle invalid department names. During initialization, if a provided department name does not match 'IT dept' or 'Management dept', the department number is set to -1. When 'showDetails' is called, it checks if `deptNo` is -1, and if so, prints out 'Not a valid Record' .
Interfaces play a crucial role in managing project assignments, especially with the 'Developer' class implementing the 'IProjectAssignable' interface, which provides method signatures for 'assignToProject' and 'getAssignedProjects'. This allows the 'Developer' class to maintain a project list and handle assignments dynamically. The 'Manager' and 'HRStaff' classes do not implement this interface, demonstrating selective capacity to be assigned projects, thereby encapsulating specific roles into interfaces .
The Java College management system uses the 'setDeptNo' method within the 'Department' class to ensure valid department names. This method checks if the input department name matches 'IT dept' or 'Management dept' using an 'if-else' statement. If it matches, it assigns appropriate department numbers (10 or 20, respectively); otherwise, it sets the department number to -1, logging 'Not a valid Record' to ensure input fidelity .
Polymorphism is demonstrated in the program by creating an array of the base class type 'Employee' which holds objects of 'Developer', 'Manager', and 'HRStaff'. Each of these objects overrides the 'calculateSalary' method to provide a class-specific implementation, allowing the same method call to behave differently based on the object type. Additionally, the 'displayInfo' method is called on each object showing their customized implementations .
The 'HRStaff' class might be declared final to prevent other classes from extending it, ensuring a fixed and consistent implementation of HR roles within the application. This decision stabilizes the core logic associated with HR salary calculations, which is simple (baseSalary only), and no performance-based bonuses are added. Consequently, the architecture is safeguarded against changes that could introduce unexpected behaviors through subclassing .
Default methods in interfaces enhance design flexibility by allowing new methods to be added to interfaces without breaking existing implementations. In the Java College management system, the 'College' interface defines 'generalMessage' as a default method, enabling any implementing class like 'Department' to inherit and use this method without needing to override it. This ensures backward compatibility and provides the opportunity for future extensions with minimal code changes .
The 'getDetails' method uses a Scanner object to solicit user input for teacher's name, qualification, and department name. While functional, it does not handle invalid inputs or exceptions, such as misspelled department names, imposing a constraint on user input. An improvement could involve implementing more robust input validation and exception handling to provide real-time feedback for incorrect inputs, ensuring better usability and error resistance .