Project 2
Account.java
public class Account {
protected Customer customer;
protected double balance;
public Account(Customer customer, double balance) {
super();
this.customer = customer;
this.balance = balance;
}
public double getBalance() {
return 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("Withdraw: "+amount);
}
else {
System.out.println("Insufficient Balance");
}
}
}
2. Customer.Java
public class Customer {
private String name;
private String address;
public Customer(String name, String address) {
this.name = name;
this.address = address;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
}
3.RBI.java
public class RBI {
public double getInterestRate() {
return 0.0;
}
public double getWithdrawalLimit() {
return 0.0;
}
}
4.SBI.java
public class SBI extends RBI {
@Override
public double getInterestRate() {
return 0.05;
}
@Override
public double getWithdrawalLimit() {
return 50000.0;
}
}
5.ICICI.java
public class ICICI extends RBI {
@Override
public double getInterestRate() {
return 0.05;
}
@Override
public double getWithdrawalLimit() {
return 75000.0;
}
}
6.BankingApp.java
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Scanner;
public class BankingApp {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Select Bank: ");
System.out.println("1. SBI");
System.out.println("2. ICICI");
int bankChoice = scanner.nextInt();
RBI selectedBank = null;
if (bankChoice == 1) {
selectedBank = new SBI();
} else if (bankChoice == 2) {
selectedBank = new ICICI();
} else {
System.out.println("Invalid choice");
return;
}
System.out.println("Select Account Type: ");
System.out.println("1. Savings");
System.out.println("2. Current");
int accountChoice = scanner.nextInt();
System.out.println("Enter Customer Name: ");
scanner.nextLine(); // Consume the newline character
String name = scanner.nextLine();
System.out.println("Enter Customer Address: ");
String address = scanner.nextLine();
Customer customer = new Customer(name, address);
double initialBalance;
if (accountChoice == 1) {
initialBalance = 2000.0;
} else if (accountChoice == 2) {
initialBalance = 5000.0;
} else {
System.out.println("Invalid choice");
return;
}
Account account = new Account(customer, initialBalance);
System.out.println("Enter Deposit Amount: ");
double depositAmount = scanner.nextDouble();
account.deposit(depositAmount);
System.out.println("Enter Withdrawal Amount: ");
double withdrawalAmount = scanner.nextDouble();
account.withdraw(withdrawalAmount);
System.out.println("Enter Number of Years to Calculate Interest: ");
int years = scanner.nextInt();
double interestRate = selectedBank.getInterestRate();
double principal = account.getBalance();
double simpleInterest = principal * interestRate * years;
double totalAmountSimple = principal + simpleInterest;
DecimalFormat df = new DecimalFormat("#.##");
System.out.println("Simple Interest: " + df.format(simpleInterest));
System.out.println("Total Amount (Simple Interest): " + df.format(totalAmountSimple));
scanner.close();
// Save mini statement to a txt file
try {
FileWriter writer = new FileWriter("mini_statement.txt");
writer.write("Customer Name: " + customer.getName() + "\n");
writer.write("Account Balance: " + account.getBalance() + "\n");
writer.write("Interest Rate: " + interestRate + "\n");
writer.write("Simple Interest: " + simpleInterest + "\n");
writer.write("Total Amount (Simple Interest): " + totalAmountSimple + "\n");
writer.close();
System.out.println("Mini statement saved to mini_statement.txt");
} catch (IOException e) {
System.out.println("An error occurred while saving mini statement.");
e.printStackTrace();
}
}
}
OutPut:-
Select Bank:
1. SBI
2. ICICI
1
Select Account Type:
1. Savings
2. Current
1
Enter Customer Name:
aaa
Enter Customer Address:
kolhapur
Enter Deposit Amount:
2000
Deposited: 2000.0
Enter Withdrawal Amount:
500
Withdraw: 500.0
Enter Number of Years to Calculate Interest:
3
Simple Interest: 525
Total Amount (Simple Interest): 4025
Mini statement saved to mini_statement.txt
mini_statement.txt
Customer Name: aaa
Account Balance: 3500.0
Interest Rate: 0.05
Simple Interest: 525.0
Total Amount (Simple Interest): 4025.0
Customer Name: Roger
Account Balance: 54000.0
Interest Rate: 0.05
Simple Interest: 13500.0
Total Amount (Simple Interest): 67500.0