mirror of
https://github.com/Manoj-HV30/OOPS-lab-codes.git
synced 2026-05-16 19:35:25 +00:00
Added Java lab programs
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,39 @@
|
||||
import accounts.Account;
|
||||
import java.util.Scanner;
|
||||
import services.Interest;
|
||||
|
||||
public class BankDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
System.out.print("Enter Account Number: ");
|
||||
int accNo = sc.nextInt();
|
||||
sc.nextLine();
|
||||
|
||||
System.out.print("Enter Customer Name: ");
|
||||
String name = sc.nextLine();
|
||||
|
||||
System.out.print("Enter Initial Balance: ");
|
||||
double balance = sc.nextDouble();
|
||||
|
||||
Account acc = new Account(accNo, name, balance);
|
||||
|
||||
System.out.print("Enter amount to deposit: ");
|
||||
double dep = sc.nextDouble();
|
||||
acc.deposit(dep);
|
||||
|
||||
System.out.print("Enter amount to withdraw: ");
|
||||
double wd = sc.nextDouble();
|
||||
acc.withdraw(wd);
|
||||
|
||||
Interest interest = new Interest();
|
||||
double updatedBalance = interest.applyInterest(acc.getBalance());
|
||||
|
||||
System.out.println("\n--- Account Details After Interest ---");
|
||||
acc.displayAccountDetails();
|
||||
System.out.println("Balance after interest: " + updatedBalance);
|
||||
|
||||
sc.close();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
package accounts;
|
||||
|
||||
public class Account {
|
||||
|
||||
private int accountNumber;
|
||||
private String customerName;
|
||||
private double balance;
|
||||
|
||||
public Account(int accountNumber, String customerName, double balance) {
|
||||
this.accountNumber = accountNumber;
|
||||
this.customerName = customerName;
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public void deposit(double amount) {
|
||||
balance += amount;
|
||||
System.out.println("Amount deposited: " + amount);
|
||||
}
|
||||
|
||||
public void withdraw(double amount) {
|
||||
if (amount <= balance) {
|
||||
balance -= amount;
|
||||
System.out.println("Amount withdrawn: " + amount);
|
||||
} else {
|
||||
System.out.println("Insufficient balance!");
|
||||
}
|
||||
}
|
||||
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void displayAccountDetails() {
|
||||
System.out.println("Account Number: " + accountNumber);
|
||||
System.out.println("Customer Name: " + customerName);
|
||||
System.out.println("Balance: " + balance);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,10 @@
|
||||
package services;
|
||||
|
||||
public class Interest {
|
||||
|
||||
private static final double RATE = 0.05; // 5% interest
|
||||
|
||||
public double applyInterest(double balance) {
|
||||
return balance + (balance * RATE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user