0% found this document useful (0 votes)
3 views10 pages

OOPLAB3

The document outlines a lab worksheet for Object Oriented Programming and Design, detailing tasks related to string operations, inheritance, exception handling, and collections. It includes specific coding tasks such as implementing an Employee class, creating an inheritance hierarchy, handling exceptions for performance ratings, and managing an employee database using ArrayList and HashMap. Each task requires the implementation of various programming concepts and techniques in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

OOPLAB3

The document outlines a lab worksheet for Object Oriented Programming and Design, detailing tasks related to string operations, inheritance, exception handling, and collections. It includes specific coding tasks such as implementing an Employee class, creating an inheritance hierarchy, handling exceptions for performance ratings, and managing an employee database using ArrayList and HashMap. Each task requires the implementation of various programming concepts and techniques in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

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:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy