Added Java lab programs

This commit is contained in:
2025-12-17 16:36:20 +05:30
parent ac2904f5db
commit 2f4beade3b
46 changed files with 882 additions and 0 deletions
Binary file not shown.
+39
View File
@@ -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.
+38
View File
@@ -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.
+10
View File
@@ -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);
}
}