0% found this document useful (0 votes)
33 views3 pages

Banking Application

Uploaded by

bsse2380220
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)
33 views3 pages

Banking Application

Uploaded by

bsse2380220
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/ 3

Name: Abdul Rafay

Registration Number: 2380220


Program: BSSE 2-D

Assignment
Program:
class Account {
protected String accountNumber;
protected double balance;

public Account(String accountNumber, double balance) {


this.accountNumber = accountNumber;
this.balance = balance;
}

public void deposit(double amount) {


balance += amount;
System.out.println("Deposited: " + amount);
}

public void withdraw(double amount) {


if (balance >= amount) {
balance -= amount;
System.out.println("Withdrawn: " + amount);
} else {
System.out.println("Insufficient funds");
}
}

public void checkBalance() {


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

class SavingsAccount extends Account {


private static final double INTEREST_RATE = 0.012;

public SavingsAccount(String accountNumber, double balance) {


super(accountNumber, balance);
}

public void calculateInterest() {


double interest = balance * INTEREST_RATE;
balance += interest;
System.out.println("Interest added: " + interest);
}
}

class CurrentAccount extends Account {


private static final double OVERDRAFT_LIMIT = 100000;

public CurrentAccount(String accountNumber, double balance) {


super(accountNumber, balance);
}

@Override
public void withdraw(double amount) {
if (balance + OVERDRAFT_LIMIT >= amount) {
balance -= amount;
System.out.println("Withdrawn: " + amount);
} else {
System.out.println("Exceeds overdraft limit");
}
}
}

import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Creating a Savings Account


System.out.println("Enter Savings Account details:");
System.out.print("Account Number: ");
String savingsAccNumber = scanner.nextLine();
System.out.print("Initial Balance: ");
double savingsInitialBalance = scanner.nextDouble();
SavingsAccount savingsAccount = new
SavingsAccount(savingsAccNumber, savingsInitialBalance);

// Creating a Current Account


System.out.println("\nEnter Current Account details:");
System.out.print("Account Number: ");
String currentAccNumber = scanner.nextLine();
currentAccNumber = scanner.nextLine();
System.out.print("Initial Balance: ");
double currentInitialBalance = scanner.nextDouble();
CurrentAccount currentAccount = new
CurrentAccount(currentAccNumber, currentInitialBalance);

// Performing operations on Savings Account


System.out.println("\nOperations on Savings Account:");
System.out.print("Enter deposit amount for Savings Account: ");
double savingsDepositAmount = scanner.nextDouble();
savingsAccount.deposit(savingsDepositAmount);
System.out.print("Enter withdrawal amount for Savings Account:
");
double savingsWithdrawAmount = scanner.nextDouble();
savingsAccount.withdraw(savingsWithdrawAmount);

savingsAccount.calculateInterest();

savingsAccount.checkBalance();

// Performing operations on Current Account


System.out.println("\nOperations on Current Account:");
System.out.print("Enter deposit amount for Current Account: ");
double currentDepositAmount = scanner.nextDouble();
currentAccount.deposit(currentDepositAmount);

System.out.print("Enter withdrawal amount for Current Account:


");
double currentWithdrawAmount = scanner.nextDouble();
currentAccount.withdraw(currentWithdrawAmount);

currentAccount.checkBalance();

// Closing the scanner


scanner.close();
}
}

Output:

You might also like