Project 2
package Firstprogram;
import java.util.Scanner;
class Customer {
String name;
String accountType;
String dob;
}
class Account {
String bankName;
String accountType;
double balance;
int accountNumber;
Customer customer;
}
class RBI {
double interestRate;
double withdrawalLimit;
}
class SBI extends RBI {
public SBI() {
interestRate = 0.05;
withdrawalLimit = 20000;
}
}
class ICICI extends RBI {
public ICICI() {
interestRate = 0.05;
withdrawalLimit = 25000;
}
}
class PNB extends RBI {
public PNB() {
interestRate = 0.05;
withdrawalLimit = 15000;
}
}
public class BankManagementSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Want to open an account?");
String answer = scanner.next();
if (answer.equalsIgnoreCase("yes")) {
System.out.println("Insert name, type of account and date of birth:");
Customer customer = new Customer();
customer.name = scanner.next();
customer.accountType = scanner.next();
customer.dob = scanner.next();
System.out.println("In which bank you want to open the account?");
String bankName = scanner.next();
RBI rbi;
switch (bankName) {
case "SBI":
rbi = new SBI();
break;
case "ICICI":
rbi = new ICICI();
break;
case "PNB":
rbi = new PNB();
break;
default:
System.out.println("Invalid bank name!");
return;
}
System.out.println("What type of account you want to open (Saving/Current)?");
String accountType = scanner.next();
Account account = new Account();
account.bankName = bankName;
account.accountType = accountType;
account.customer = customer;
if (accountType.equalsIgnoreCase("saving")) {
account.balance = 2000;
} else if (accountType.equalsIgnoreCase("current")) {
account.balance = 5000;
} else {
System.out.println("Invalid account type!");
return;
}
System.out.println("Account has been opened and account no is: " + account.accountNumber);
System.out.println("Want to print mini statement?");
answer = scanner.next();
if (answer.equalsIgnoreCase("yes")) {
// Save mini statement in .text file
System.out.println("Mini statement saved successfully!");
}
System.out.println("Calculate interest?");
answer = scanner.next();
if (answer.equalsIgnoreCase("yes")) {
System.out.println("For how many years you want to calculate the interest?");
int time = scanner.nextInt();
double interestRate = rbi.interestRate;
double balance = account.balance;
if (accountType.equalsIgnoreCase("current")) {
// Compounded twice a year (half yearly)
interestRate = Math.pow((1 + interestRate / 2), 2) - 1;
}
double interest = balance * interestRate * time;
double totalAmount = balance + interest;
System.out.println("Total interest: " + interest);
System.out.println("Total amount: " + totalAmount);
}
} else if (answer.equalsIgnoreCase("no")) {
System.out.println("Thank you!");
} else {
System.out.println("Invalid answer!");
}
}
}