- Understand Exceptions in Java.
- Implement try/catch/finally to handle Exceptions in Java.
- Understand and implement custom exceptions in Java.
- Comment the
displayProfile(String department)
method in both thePayroll
Interface and its implementation in thePayrollImpl
class. - In
Main.java
, invokedisplayProfile(Employee employee)
by passingnull
as the parameter. - Handle the
NullPointerException
using a try/catch block. - Handle all possible exceptions in all methods of the
PayrollImpl
class.
- Create a new package
com.trainingmug.employee.exception
. - Under this package, create a new Exception class named
InvalidBankAccountException
. - Override the constructor
public InvalidBankAccountException(String message)
with a message. - In
Employee.java
:- Add the
bankAccountNo
(String) property. - Update the argument constructor to include the
bankAccountNo
property. - Generate getter and setter methods for this property.
- Print the
bankAccountNo
in thedisplayProfile()
method.
- Add the
- In
Developer.java
andDesigner.java
:- Add
bankAccountNo
in the constructor and pass it to the superclass constructor. - Print the
bankAccountNo
by invokinggetBankAccountNo()
in thedisplayProfile()
method.
- Add
- In
Main.java
, pass thebankAccountNo
values for allEmployee
,Developer
, andDesigner
objects. - In
Payroll.java
, create the following method:boolean processSalary(Employee employee) throws InvalidBankAccountException;
- In
PayrollImpl.java
, implement the above method with the following rules:- If the
bankAccountNo
of the Employee isnull
or not 11 characters in length, throwInvalidBankAccountException
with the appropriate message. - If the
bankAccountNo
is valid, display a message "Net Salary : $XXXX is successfully processed to XXXXX" and returntrue
.
- If the
- In
Main.java
, invoke theprocessSalary()
method by passing existingDeveloper
andDesigner
objects. - Handle the
InvalidBankAccountException
using a try/catch block and display the exception message in the catch block. - Create a
Developer
object withbankAccountNo
asnull
and invoke theprocessSalary()
method. - Observe the output:
"Hey XXXXXX, Invalid Bank Account, Please provide the proper Bank Account Number to process your salary."
- Create another
Developer
object withbankAccountNo
as 7 digits and invoke theprocessSalary()
method. - Observe the output:
"Hey XXXXXX, Invalid Bank Account, Please provide the proper Bank Account Number to process your salary."
This README provides a high-level overview of the tasks and requirements for exception handling and custom exceptions in the Java application.