Lab Work Sheet 3
Aniket Srivastava 2022WB8663 Object Oriented Programming and Design
Question 1: String Operations & Manipulations
Task: Implement a Employee class that performs the following operations:
a) Accept and store an employee’s name, ID, and designation using String.
b) Convert the name to uppercase and display it.
c) Compare two employee names to check if they are identical.
d) Extract and display initials of the employee's name using char array.
e) Implement StringBuffer or StringBuilder for appending a department
code to the employee’s name.
Code :-
Output:-
Question 2: Inheritance & Polymorphism
Task: Implement an inheritance hierarchy:
a) Create a base class Employee with attributes (name, ID, salary).
b) Derive subclasses Manager and Developer that override a method
showRole().
c) Use super keyword to access parent class methods.
d) Implement runtime polymorphism: Use an Employee reference to call
showRole() on Manager and Developer.
Code:-
Output:-
Question 3: Exception Handling in Performance Ratings
Task: Implement a system where:
a) The PerformanceRating class assigns ratings (1-5) to employees.
b) If an invalid rating (<1 or >5) is given, a custom exception
InvalidRatingException is thrown.
c) Use try-catch-finally to handle this exception gracefully.
d) Use throws in method declaration where needed.
Code:-
Output:-
Question 4: Collections & Employee Sorting
Task: Implement an Employee Database using ArrayList:
a) Store multiple employees in an ArrayList<Employee>.
b) Use Comparator and Comparable to sort employees by salary.
c) Display employees in sorted order.
Implement HashMap<Integer, Employee> to store employees based on their IDs.
Code:-
Output:-