Project 2
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class RBI {
public static void main(String[] args) {
System.out.println("************Welcome to National Banking System*******************");
System.out.println("\n");
System.out.println("Do you want to open an account: 1.Yes 2.No");
Scanner sc = new Scanner(System.in);
String choice = sc.nextLine();
if (choice.equalsIgnoreCase("yes")) {
CreateAccount ac = new CreateAccount();
ac.CreateAccount();
}
if (choice.equalsIgnoreCase("No")) {
BankAccount bc = new BankAccount();
bc.showMenu();
}
}
}
class CreateAccount {
String name;
String accountName;
String dob;
String accountType;
String bank;
void CreateAccount() {
Scanner sc = new Scanner(System.in);
System.out.println("In which bank you to open it 1.Axis 2.HDFC 3.SBI");
int choicebank = sc.nextInt();
if (choicebank == 1) {
bank = "Axis";
}
if (choicebank == 1) {
bank = "HDFC";
}
if (choicebank == 1) {
bank = "SBI";
}
System.out.println("Please enter your name: ");
name = sc.nextLine();
sc.nextLine();
System.out.println("Please enter your DOB: ");
dob = sc.nextLine();
System.out.println("What type of account you want to open 1.Saving 2.Current");
int choice = sc.nextInt();
if (choice == 1) {
accountType = "Saving";
}
if (choice == 2) {
accountType = "Current";
}
System.out.println("Your accont has been openen with following details");
System.out.println("Bank " + bank);
System.out.println("User Name " + name);
System.out.println("dob " + dob);
System.out.println("AccountType " + accountType);
System.out.println("AccountNo " + Math.random());
System.out.println("\n");
BankAccount obj = new BankAccount();
obj.showMenu();
}
}
class BankAccount {
int balance;
int previousTransaction;
String customerName;
String CustId;
String accntType;
double totalInterest;
void CalculateInterest(double balance) {
System.out.println("What type of account you have: 1.Saving 2.Current");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
if (choice == 1) {
accntType = "Current";
int r = 5;
int t;
System.out.println("Enter your to calculate interest");
t = sc.nextInt();
double finalAmount = balance * (1 + r * t);
totalInterest = finalAmount - balance;
System.out.println("Total interest earned is: " + totalInterest);
}
if (choice == 2) {
accntType = "Saving";
int r = 8;
int t, n;
System.out.println("Enter your to calculate interest");
t = sc.nextInt();
System.out.println("Enter the frequency that interest has been compound in a year");
n = sc.nextInt();
double finalAmount = balance * (Math.pow((1 + r / n), n * t));
totalInterest = finalAmount - balance;
System.out.println("Total interest earned is: " + totalInterest);
sc.close();
}
}
void deposit(int amount) {
if (amount != 0) {
balance += amount;
System.out.println("Balance after deposit : " + balance);
previousTransaction = amount;
}
}
void withdraw(int amount) {
if (amount != 0) {
balance -= amount;
System.out.println("Balance after withdraw : " + balance);
previousTransaction = -amount;
}
}
void getPreviousTransaction() {
FileOutputStream filepath;
PrintStream print;
try {
filepath = new FileOutputStream("PreviouseTransaction.txt");
print = new PrintStream(filepath);
if (previousTransaction > 0) {
print.append("Deposited : " + previousTransaction);
}
if (previousTransaction < 0) {
print.append("Withdrawn : " + previousTransaction);
System.out.println("Withdrawn : " + Math.abs(previousTransaction));
} else {
System.out.println("No Transaction Occured");
}
print.close();
} catch (Exception e) {
System.out.println("Error Occured " + e);
}
}
void showMenu() {
char option = '\0';
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the menu");
System.out.println("\n");
System.out.println("A. Check Balance");
System.out.println("B. Deposit Amount");
System.out.println("C. Withdraw Amount");
System.out.println("D. See Previous Transaction");
System.out.println("E. Calculate Interest");
System.out.println("F. Exit");
do {
System.out.println("----------");
System.out.println(" Enter the option");
System.out.println("----------");
option = sc.next().charAt(0);
System.out.println("\n");
switch (option) {
case 'A':
System.out.println("---------");
System.out.println("Balance = " + balance);
System.out.println("-----------");
System.out.println("\n");
break;
case 'B':
System.out.println("---------");
System.out.println("Enter the amount you want to deposit");
int amount = sc.nextInt();
deposit(amount);
System.out.println("\n");
break;
case 'C':
System.out.println("---------");
System.out.println("Enter the amount you want to withdraw");
int amount1 = sc.nextInt();
withdraw(amount1);
System.out.println("\n");
break;
case 'D':
System.out.println("---------");
getPreviousTransaction();
System.out.println("\n");
break;
case 'E':
System.out.println("---------");
CalculateInterest(balance);
System.out.println("\n");
break;
case 'F':
System.out.println("---------");
break;
default:
System.out.println("Enter Invalid option. Please enter Again");
break;
}
} while (option != 'F');
System.out.println("Thank you for using our service");
sc.close();
}
}