0% found this document useful (0 votes)
11 views9 pages

OOP Assignment # 02( Lab- 2)

The document presents an assignment for a Bank Management System in Object-Oriented Programming, authored by Kainat Hanif. It includes a Java implementation of a 'BankAccount' class with methods for account management, such as deposit, withdrawal, and balance comparison. The main class facilitates user interaction to create accounts and perform transactions, displaying the results at the end.

Uploaded by

kainathanif658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views9 pages

OOP Assignment # 02( Lab- 2)

The document presents an assignment for a Bank Management System in Object-Oriented Programming, authored by Kainat Hanif. It includes a Java implementation of a 'BankAccount' class with methods for account management, such as deposit, withdrawal, and balance comparison. The main class facilitates user interaction to create accounts and perform transactions, displaying the results at the end.

Uploaded by

kainathanif658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

ASSIGNMENT # 02

Submitted to:
Sir. Shehzad Ali

Submitted by:
Kainat Hanif

Registration no:
SP24-BSE-005-3-A

Subject:
Object-Oriented-Programming

Date of Submission:
29/03/25
Question # 01:

Bank Management System

Class Name(Bank Account)

package Managment;

public class BankAccount {

private String accountHolderName;

private int accountNumber;

private double balance;

// parameterized constructor

BankAccount ( String a, int n, double b) {

accountHolderName = a;

accountNumber = n;

balance = b;

// Getter methods

public String getAccountHolderName() {

return accountHolderName;

public int getAccountNumber() {

return accountNumber;

public double getBalance() {

return balance;

}
public boolean isSameAccountHolder(BankAccount other) {

String thisName = this.accountHolderName.toLowerCase();

String otherName = other.accountHolderName.toLowerCase();

return thisName.equals(otherName);

//Comparing balance between two accounts

public String compareBalances(BankAccount other) {

double difference = this.balance - other.balance;

if (difference > 0) {

return this.accountHolderName;

if (difference < 0) {

return other.accountHolderName;

return "Both accounts have equal balance";

// Setter methods

public void setAccountHolderName(String newName) {

if (newName != null && newName.length() > 0) {

accountHolderName = newName;

} else {

System.out.println("Name cannot be empty");

}
// Add Money

public void deposit(double amount) {

if (amount <= 0) {

System.out.println("Deposit amount must be positive.");

return;

balance = balance + amount;

System.out.println("Deposited: " + amount + " $");

System.out.println("New Balance: " + balance + " $");

//Withdraw Money

public void withdraw(double amount) {

// Check if amount is valid

if (amount <= 0) {

System.out.println("Please enter a positive amount");

return;

// Check if enough money is available

if (balance < amount) {

System.out.println("Not enough money in account");

return;

}
// If all checks pass, do the withdrawal

balance = balance - amount;

System.out.println("Withdrew: " + amount + " $");

System.out.println("New balance: " + balance + " $");

//Display Function

void display () {

System.out.println("Account Information.");

System.out.println("Holder: " + accountHolderName);

System.out.println("Number: " + accountNumber);

System.out.println("Balance: " + balance);

Main (Runner) Class

package Managment;

import java .util.*;

public class BankMnagementSystem {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("Simple Bank Management System");

System.out.println("_____________________________________");

//Taking input from the user for 1st account

System.out.println("Account 1:");
System.out.println("Enter account holder name: ");

String name1 = s.next();

System.out.println("Enter account number: ");

int num1 = s.nextInt();

System.out.println("Enter current balance: ");

double balance1 = s.nextDouble();

//Creating an object for Account 1

BankAccount account1 = new BankAccount(name1, num1, balance1);

//Taking input from the user for 2nd account

System.out.println("Account 2:");

System.out.println("Enter account holder name: ");

String name2 = s.next();

System.out.println("Enter account number: ");

int num2 = s.nextInt();

System.out.println("Enter current balance: ");

double balance2 = s.nextDouble();

//Creating an object for Account 2

BankAccount account2 = new BankAccount(name2, num2, balance2);

//Perform Transactions

System.out.println("\nPerforming Transactions....");

//Deposit to Account 1
System.out.println("Enter deposit ammount for " +
account1.getAccountHolderName() + ": $");

double depositAccount = s.nextDouble();

account1.deposit(depositAccount);

//Withdraw from account 2

System.out.println("Enter withdraw ammount for " +


account2.getAccountHolderName() + ": $");

double withdrawAmount = s.nextDouble();

account2.withdraw(withdrawAmount);

// Comparing two accounts

System.out.println("\nComparion between two accounts: ");

System.out.println("___________________________________________");

if (account1.isSameAccountHolder(account2)) {

System.out.println("Both accounts belong to the same person.");

} else {

System.out.println("These accounts belong to different people.");

String result = account1.compareBalances(account2);

System.out.println("Balance comparison: " + result);

// Display final account info

account1.display();

account2.display();
}

Output:

You might also like