The objective of this module is to get hands-on experience with the following topics:
- Introduction to Abstraction
- Abstract classes and interfaces
- Access Modifiers (public, private, protected)
- Understand and implement abstraction in Java.
Create an interface Payroll
and implement the following abstract methods in a PayrollImpl
class.
void displayProfile(Employee employee);
float calculateNetSalary(Employee employee);
float calculateNetSalaryAfterIncrement(Employee employee);
void displayProfile(int empId);
void displayProfile(float fromSalaryRange, float toSalaryRange);
void displayProfile(String department);
-
Create an interface named
Payroll
with the following methods:void displayProfile(Employee employee);
float calculateNetSalary(Employee employee);
float calculateNetSalaryAfterIncrement(Employee employee);
void displayProfile(int empId);
void displayProfile(float fromSalaryRange, float toSalaryRange);
void displayProfile(String department);
-
Implement the
PayrollImpl
class that implements thePayroll
interface. -
Override all the methods with the
@Override
annotation.Method Instructions:
-
displayProfile(Employee employee)
- Action: Call
employee.displayProfile()
.
- Action: Call
-
calculateNetSalary(Employee employee)
- Action: Call and return
employee.calculateNetSalary()
.
- Action: Call and return
-
calculateNetSalaryAfterIncrement(Employee employee)
- Action: Call and return
employee.calculateNetSalaryAfterIncrement()
.
- Action: Call and return
-
displayProfile(int empId)
- Action: Print a message to indicate displaying the profile for the given Employee ID.
- Example:
System.out.println("This method display the employee profile with Employee ID ");
-
displayProfile(float fromSalaryRange, float toSalaryRange)
- Action: Print a message to indicate displaying profiles within the given salary range.
- Example:
System.out.println("This method display all employee profiles from and to given salary ranges");
-
displayProfile(String department)
- Action: Print a message to indicate displaying profiles for the given department.
- Example:
System.out.println("This method display all the employee profiles from a given department");
-
-
In the Main class, create the
PayrollImpl
object and invoke all the methods by passing theDeveloper
andDesigner
objects as implemented in the previous lab.