HET Ka OOP
HET Ka OOP
Submitted By
Het Patel (236400316124)
DIPLOMA ENGINEERING
in
INDEX
Content Page no
Introduction 3
Project Explanation 4-5
Code 6-14
Output 15
Conclusion 16
P age |3
1. INTRODUCTION
2. PROJECT EXPLANATION
The application runs through a console-based menu system where the user
can choose an operation. When the user selects an option, the corresponding
method is called to perform the action. The system ensures basic validation,
such as checking if the withdrawal amount exceeds the available balance,
thus mimicking essential banking rules.
P age |5
Cash Deposit: Allows users to deposit money into their account and
updates the balance accordingly.
Code Explanation
1. Import Statements
import java.io.IOException;
import java.util.Scanner;
java.util.Scanner is used for reading user input from the console.
java.io.IOException handles invalid input-related exceptions during I/O operations.
3. BankOperations Interface
interface BankOperations {
void viewAccountDetails();
void deposit(double amount);
void withdraw(double amount) throws InsufficientBalanceException;
}
This interface defines three core banking operations:
o viewAccountDetails()
o deposit()
o withdraw() (can throw InsufficientBalanceException)
It ensures that any implementing class provides definitions for these methods.
P a g e | 11
4. BankAccount Class
class BankAccount implements BankOperations {
private String name, type, accountNumber, password;
private double balance;
Represents an individual bank account with personal information and balance.
Implements the BankOperations interface.
✅ Constructor
public BankAccount(String name, String type, String number, String password, double
balance) {
...
}
Initializes account details when a new account is created.
✅ getAccountNumber()
public String getAccountNumber() {
return accountNumber;
}
Returns the account number (used for login).
✅ authenticate()
public boolean authenticate(String pass) {
return this.password.equals(pass);
}
Validates password during login.
✅ viewAccountDetails()
public void viewAccountDetails() {
...
}
Displays user name, account type, number, and balance.
P a g e | 12
✅ deposit()
public void deposit(double amount) {
...
}
Adds money to the account balance after validation.
✅ withdraw()
public void withdraw(double amount) throws InsufficientBalanceException {
...
}
Allows withdrawal if funds are sufficient. Otherwise, throws a custom exception.
✅ main() Method
public static void main(String[] args) {
...
}
Displays welcome message.
Calls methods to:
o Create an account
o Login
o Show a menu repeatedly (until user exits).
Handles invalid input via IOException.
P a g e | 13
✅ createAccount()
private static void createAccount() throws IOException {
...
}
Collects user data (name, type, number, password, initial balance).
Validates input format (e.g., balance must be a number).
Creates a new BankAccount object.
✅ login()
private static boolean login() throws IOException {
...
}
Prompts for account number and password.
Allows 3 attempts for successful login.
Returns true if authenticated, otherwise false.
✅ showMenu()
private static void showMenu() {
...
}
Displays a simple menu:
1. View account
2. Deposit
3. Withdraw
4. Exit
P a g e | 14
✅ handleDeposit()
private static void handleDeposit() throws IOException {
...
}
Prompts user for deposit amount.
Calls deposit() method of BankAccount.
✅ handleWithdraw()
private static void handleWithdraw() throws IOException {
...
}
Prompts user for withdrawal amount.
Handles InsufficientBalanceException if withdrawal amount exceeds balance.
✅ getValidAmount()
private static double getValidAmount(String prompt) throws IOException {
...
}
Validates that user enters a numeric amount for deposit or withdrawal.
Throws IOException on invalid input (non-numeric).
P a g e | 15
4. OUTPUT / RESULT
P a g e | 16
5. CONCLUSION
This project not only highlights the importance of input validation and
secure authentication but also simulates real-world banking functionalities in
a console-based environment. Overall, it lays a strong foundation for further
enhancements like file-based data storage, GUI integration, and transaction
histories in future iterations.