Final j Component
Final j Component
REVIEW
TEAM MEMBERS:
KISHORE.S - 21MIS0280
KAUSHIK.K – 21MIS0332
NARESH.R – 21MIS0354
1.Problem Statement:
• Banking customers frequently encounter delays and errors in transaction
processing and account management due to outdated and manual banking
procedures.
• The government is concerned about the inefficiencies in the current
system and seeks to develop a software solution that can automate and
streamline banking operations. The new system should simplify complex
financial services, ensure accurate and timely processing of transactions,
and provide a consistent user experience, reducing the risk of human
errors and operational bottlenecks.
• Involvement:
o An InterestCalculationContext class will use different interest
calculation strategies (e.g., fixed-rate, variable-rate) depending on
the account type (savings, fixed deposit, etc.).
o This pattern enables the bank to modify interest calculation
methods without altering the underlying structure, ensuring
adaptability to new financial products or regulatory changes
.
3. Chain of Responsibility Pattern:
• Purpose: Processes requests through a chain of handlers, where each
handler decides whether to process the request or pass it to the next
handler
• Involvement:
o A LoanApprovalChain will be implemented where a loan request
is passed through various stages (e.g., credit check, managerial
approval, legal review) before a final decision is made.
This pattern allows for flexible and manageable processing of multi-
step operations, ensuring that each request is handled according to
specific criteria.
5. Details of design pattern with respect to the scenario (Intent,
Structure) :
1. Facade Pattern
Intent:
The Facade Pattern provides a unified interface to a set of interfaces
in a subsystem. It simplifies the interaction between the client and the
complex subsystems involved in the banking operations. By using the
Facade, the client doesn’t need to deal with the intricacies of how
various banking services (like account management, loan processing,
and transaction history) work. It provides a simplified interface that
shields the client from the underlying complexity.
In our scenario, the Facade pattern is used to handle complex
banking operations such as opening an account, processing a loan,
and viewing transaction history in a unified manner.
Structure:
• Client: The Main class where user inputs are processed.
• Facade: The BankingFacade class that simplifies the banking
operations.
• Subsystems: The actual classes that perform the operations:
o AccountService: Manages the process of opening an
account.
o LoanService: Manages the process of processing loans.
o TransactionService: Manages the retrieval and viewing
of transaction history.
2. Strategy Pattern
Intent:
The Strategy Pattern defines a family of algorithms (strategies),
encapsulates each one, and makes them interchangeable. The strategy
pattern allows algorithms to vary independently from the clients that
use them. This pattern is useful when there are multiple ways to
perform a certain task, and the best algorithm can be selected at
runtime.
In our banking scenario, the Strategy Pattern is used to calculate
interest in two different ways:
• FixedRateInterestStrategy: A fixed interest rate is applied.
• VariableRateInterestStrategy: A variable interest rate is
applied, depending on user input.
Structure:
• Context: The InterestCalculationContext class, which maintains
a reference to the current interest calculation strategy.
• Strategy Interface: InterestCalculationStrategy interface that
defines the method for calculating interest.
• Concrete Strategies: Classes that implement different interest
calculation methods:
o FixedRateInterestStrategy: A strategy for calculating fixed
rate interest.
o VariableRateInterestStrategy: A strategy for calculating
variable rate interest.
3. Chain of Responsibility Pattern
Intent:
The Chain of Responsibility Pattern is used to allow more than one
handler (object) to process a request. The request is passed along a
chain of handlers, and each handler either processes the request or
passes it to the next handler in the chain.
In the banking system, the Chain of Responsibility is used in the
loan approval process. A loan request must go through a series of
checks (credit check, manager approval, legal review), and each
handler in the chain either approves or rejects the loan or forwards it
to the next handler.
Structure:
• Handler Interface: LoanApprovalHandler, the base interface
for all handlers in the chain.
• Concrete Handlers: Specific handlers that process parts of the
loan approval process:
o CreditCheckHandler: Handles the credit score validation.
o ManagerApprovalHandler: Handles approval from the
manager.
o LegalReviewHandler: Handles the legal review of the
loan.
• Request: LoanRequest, encapsulates the loan details (amount,
credit score, etc.).
6. Code for each component:
1. Façade pattern:
Main class:
import java.util.Scanner;
while (!exit) {
System.out.println("6. Exit");
switch (choice) {
case 1:
openAccount(bankingFacade, scanner);
break;
case 2:
processLoan(bankingFacade, scanner);
break;
case 3:
bankingFacade.viewTransactionHistory();
break;
case 4:
calculateInterest(interestContext, scanner);
break;
case 5:
loanApprovalProcess(scanner);
break;
case 6:
exit = true;
printReceipt();
System.out.println("Exiting the Banking System. Goodbye!");
break;
default:
System.out.println();
scanner.close();
accountType = scanner.nextLine();
bankingFacade.openAccount(accountType);
loanType = scanner.nextLine();
bankingFacade.processLoan(loanType);
loanAmount = scanner.nextDouble();
if (interestChoice == 1) {
interestContext.setStrategy(new FixedRateInterestStrategy());
} else if (interestChoice == 2) {
interestContext.setStrategy(new VariableRateInterestStrategy(variableRate));
} else {
return;
interest = interestContext.calculateInterest(loanAmount);
// Method to handle the loan approval process using Chain of Responsibility pattern
loanAmount = scanner.nextDouble();
creditScore = scanner.nextInt();
LoanRequest loanRequest = new LoanRequest(loanAmount, creditScore);
creditCheck.setNextHandler(managerApproval);
managerApproval.setNextHandler(legalReview);
creditCheck.processRequest(loanRequest);
if (accountType != null) {
} else {
if (loanType != null) {
} else {
System.out.println("=============================");
BankingFacade class:
class BankingFacade {
public BankingFacade() {
accountService.openAccount(accountType);
loanService.processLoan(loanType);
transactionService.viewTransactionHistory();
}
2. Strategy pattern:
InterestCalculationContext class:
class InterestCalculationContext {
this.strategy = strategy;
return strategy.calculateInterest(amount);
InterestCalculationStrategy class:
interface InterestCalculationStrategy {
FixedRateInterestStrategy class:
class FixedRateInterestStrategy implements InterestCalculationStrategy {
@Override
}
3. Chain Of Responsibility pattern:
LoanApprovalHandler class:
abstract class LoanApprovalHandler {
this.nextHandler = nextHandler;
if (nextHandler != null) {
nextHandler.processRequest(request);
CreditCheckHandler class:
class CreditCheckHandler extends LoanApprovalHandler {
@Override
super.processRequest(request);
} else {
ManagerApprovalHandler class:
class ManagerApprovalHandler extends LoanApprovalHandler {
@Override
} else {
super.processRequest(request);
LegalReviewHandler class:
class LegalReviewHandler extends LoanApprovalHandler {
@Override
}
7. Collaboration of code (Flow):
1. Facade Pattern Collaboration Flow
Objective:
The Facade pattern simplifies interactions with various subsystems
(Account, Loan, Transaction) by providing a unified interface
(BankingFacade) for common banking operations like opening an
account, processing loans, viewing transaction history, etc.
Participants:
• Client: Main class
• Facade: BankingFacade class
• Subsystems:
o AccountService
o LoanService
o TransactionService
Flow of Collaboration:
1. Client Interaction (Main Class):
o The user chooses an operation from the menu (e.g.,
opening an account, processing a loan, etc.).
o The Main class doesn't directly interact with any
subsystem services. Instead, it interacts with the
BankingFacade, which provides a high-level, simplified
interface to the banking services.
2. Facade Interaction (BankingFacade):
o The Main class calls a method on the BankingFacade,
such as openAccount(), processLoan(), or
viewTransactionHistory().
o The BankingFacade then interacts with the corresponding
subsystem class (such as AccountService, LoanService,
TransactionService) to perform the actual operation.
3. Subsystems Interaction:
o Each subsystem class (AccountService, LoanService,
TransactionService) performs the required task and returns
the results back to the BankingFacade.
o The BankingFacade then forwards the results to the client
(Main class).
Example Flow:
1. Client (Main) calls BankingFacade.openAccount().
2. BankingFacade forwards the request to AccountService,
which handles the account creation.
3. The result is returned to BankingFacade, which forwards it to
the Client (Main).
Client (Main) → BankingFacade → Subsystem (AccountService,
LoanService, TransactionService)
2. Strategy Pattern Collaboration Flow
Objective:
The Strategy pattern enables the interest calculation mechanism to be
flexible by allowing different strategies (fixed or variable interest
rates) to be selected at runtime based on user input.
Participants:
• Context: InterestCalculationContext
• Strategy Interface: InterestCalculationStrategy
• Concrete Strategies:
o FixedRateInterestStrategy
o VariableRateInterestStrategy
Flow of Collaboration:
1. Client Interaction (Main Class):
o The user chooses the interest calculation option (fixed rate
or variable rate).
o The Main class instantiates the
InterestCalculationContext.
2. Setting the Strategy:
o The Main class selects the interest calculation strategy
based on user input and sets it in the
InterestCalculationContext using the setStrategy()
method.
o The strategy can be either FixedRateInterestStrategy or
VariableRateInterestStrategy.
3. Executing the Strategy:
o When the interest needs to be calculated, the
InterestCalculationContext calls the calculateInterest()
method, which delegates the interest calculation to the
current strategy (fixed or variable).
4. Result:
o The result of the interest calculation is returned to the
Main class, where it can be displayed to the user.
Example Flow:
1. Client (Main) calls setStrategy(new
FixedRateInterestStrategy()) on InterestCalculationContext.
2. The InterestCalculationContext stores the strategy.
3. When InterestCalculationContext.calculateInterest() is called, it
forwards the request to the set strategy
(FixedRateInterestStrategy), which performs the calculation.
4. The calculated interest is returned to the Main class.
Client (Main) → InterestCalculationContext →
InterestCalculationStrategy (FixedRate or VariableRate)
3. Chain of Responsibility Pattern Collaboration Flow
Objective:
The Chain of Responsibility pattern is used in the loan approval
process to ensure that the loan request passes through various
approval stages (credit check, manager approval, legal review) before
final approval or rejection.
Participants:
• Request: LoanRequest
• Handler Interface: LoanApprovalHandler
• Concrete Handlers:
o CreditCheckHandler
o ManagerApprovalHandler
o LegalReviewHandler
Flow of Collaboration:
1. Client Interaction (Main Class):
o The user selects the loan approval process.
o The Main class creates a LoanRequest and sends it to the
first handler in the chain (CreditCheckHandler).
2. Request Processing by Handlers:
o CreditCheckHandler processes the request first by
checking the credit score.
o If the credit check is passed, the request is forwarded to
the next handler, ManagerApprovalHandler.
o ManagerApprovalHandler performs managerial
approval and, if successful, forwards the request to the
next handler, LegalReviewHandler.
3. Final Approval or Rejection:
o After passing through all the handlers in the chain, the
final decision is made, and the result is returned to the
Main class.
4. Result:
o The Main class receives the loan approval or rejection
result and displays it to the user.
Example Flow:
1. Client (Main) creates a LoanRequest and passes it to the first
handler in the chain, CreditCheckHandler.
2. CreditCheckHandler processes the request and forwards it to
ManagerApprovalHandler if successful.
3. ManagerApprovalHandler processes the request and forwards
it to LegalReviewHandler if successful.
4. LegalReviewHandler makes the final decision and returns the
result to the client.
Client (Main) → LoanApprovalHandler (CreditCheckHandler)
→ LoanApprovalHandler (ManagerApprovalHandler) →
LoanApprovalHandler (LegalReviewHandler)
8. Sample Output Screenshots:
9. Modifications given by faculty:
We were asked to add additional functionalities and connect with
MySQL Database.
Design patterns (structure with respect to scenario):
1. Facade Pattern
The Facade Pattern provides a unified interface to a set of interfaces
in a subsystem. It simplifies the interaction between the client and the
complex subsystems involved in the banking operations. By using the
Facade, the client doesn’t need to deal with the intricacies of how
various banking services (like account management, loan processing,
and transaction history) work. It provides a simplified interface that
shields the client from the underlying complexity.
In our scenario, the Facade pattern is used to handle complex
banking operations such as opening an account, processing a loan,
and viewing transaction history in a unified manner.
Structure:
• Client: The Main class where user inputs are processed.
• Facade: The BankingFacade class that simplifies the banking
operations.
• Subsystems: The actual classes that perform the operations:
o AccountService: Manages the process of opening an
account.
o LoanService: Manages the process of processing loans.
o TransactionService: Manages the retrieval and viewing
of transaction history.
2. Strategy Pattern
The Strategy Pattern defines a family of algorithms (strategies),
encapsulates each one, and makes them interchangeable. The strategy
pattern allows algorithms to vary independently from the clients that
use them. This pattern is useful when there are multiple ways to
perform a certain task, and the best algorithm can be selected at
runtime.
In our banking scenario, the Strategy Pattern is used to calculate
interest in two different ways:
• FixedRateInterestStrategy: A fixed interest rate is applied.
• VariableRateInterestStrategy: A variable interest rate is
applied, depending on user input.
Structure:
• Context: The InterestCalculationContext class, which maintains
a reference to the current interest calculation strategy.
• Strategy Interface: InterestCalculationStrategy interface that
defines the method for calculating interest.
• Concrete Strategies: Classes that implement different interest
calculation methods:
o FixedRateInterestStrategy: A strategy for calculating fixed
rate interest.
o VariableRateInterestStrategy: A strategy for calculating
variable rate interest.
3. Chain of Responsibility Pattern
The Chain of Responsibility Pattern is used to allow more than one
handler (object) to process a request. The request is passed along a
chain of handlers, and each handler either processes the request or
passes it to the next handler in the chain.
In the banking system, the Chain of Responsibility is used in the
loan approval process. A loan request must go through a series of
checks (credit check, manager approval, legal review), and each
handler in the chain either approves or rejects the loan or forwards it
to the next handler.
Structure:
• Handler Interface: LoanApprovalHandler, the base interface
for all handlers in the chain.
• Concrete Handlers: Specific handlers that process parts of the
loan approval process:
o CreditCheckHandler: Handles the credit score validation.
o ManagerApprovalHandler: Handles approval from the
manager.
o LegalReviewHandler: Handles the legal review of the
loan.
• Request: LoanRequest, encapsulates the loan details (amount,
credit score, etc.).
CODE:
MySQL coding :
CREATE DATABASE LoanManagement;
USE LoanManagement;
// MySQL Connector
class MySQLConnector {
private static final String URL =
"jdbc:mysql://localhost:3306/LoanManagement";
private static final String USER = "root"; // Replace with your
MySQL username
private static final String PASSWORD = "NareshR31#"; // Replace
with your MySQL password
switch (choice) {
case 1 -> interestRate = loanAmount * 0.05; // Fixed
rate is 5% (0.05)
case 2 -> {
System.out.print("Enter the Variable Interest Rate (in
percentage): ");
interestRate = loanAmount * (scanner.nextDouble() /
100); // Convert to decimal
}
default -> System.out.println("Invalid choice.");
}
while (true) {
System.out.println("\n--- Main Menu ---");
System.out.println("1. Bank Manager");
System.out.println("2. User");
System.out.println("3. Exit");
System.out.print("Select an option: ");
int choice = scanner.nextInt();
switch (choice) {
case 1 -> {
boolean exitAdminMenu = false;
while (!exitAdminMenu) {
System.out.println("\n--- Manager Menu ---");
System.out.println("1. View All User Loans");
System.out.println("2. Set Interest Rate");
System.out.println("3. Approve Loan");
System.out.println("4. Back to Main Menu");
System.out.print("Select an option: ");
int adminChoice = scanner.nextInt();
switch (adminChoice) {
case 1 -> loanManager.viewUserLoans();
case 2 -> loanManager.selectInterestRate();
case 3 -> loanManager.approveLoan();
case 4 -> exitAdminMenu = true;
default -> System.out.println("Invalid choice.");
}
}
}
case 2 -> {
boolean exitUserMenu = false;
boolean loggedIn = false;
int accountNumber = -1;
while (!exitUserMenu) {
System.out.println("\n--- User Menu ---");
System.out.println("1. Create Account");
System.out.println("2. Login");
System.out.println("3. Apply for Loan");
System.out.println("4. View Loan History");
System.out.println("5. Back to Main Menu");
System.out.print("Select an option: ");
int userChoice = scanner.nextInt();
switch (userChoice) {
case 1 -> accountManager.createAccount();
case 2 -> {
loggedIn = accountManager.login();
if (loggedIn) {
System.out.print("Enter your account number:
");
accountNumber = scanner.nextInt();
}
}
case 3 -> {
if (loggedIn)
loanManager.applyForLoan(accountNumber);
else System.out.println("Please login first.");
}
case 4 -> {
if (loggedIn)
transactionHistory.viewTransactionHistory(accountNumber);
else System.out.println("Please login first.");
}
case 5 -> exitUserMenu = true;
default -> System.out.println("Invalid choice.");
}
}
}
case 3 -> {
System.out.println("Exiting the system. Goodbye!");
return;
}
default -> System.out.println("Invalid choice.");
}
}
}
}
ScreenShots :
Creating a new account by entering name, password,Phone
number, address, type of account :
Login as Bank Manager and viewing all the Loan taken by all bank
users :
Database ScreenShot:
Loan Management Database :
Loans Database: