Challenge

Project 2

package BankPackage;

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class SBI {
public static void main(String[] args) {

System.out.println(">>>>> Welcome To State Bank of India <<<<<");
System.out.println("\n");
System.out.println("Do you want to open an Bank Account : 1. Yes 2. No");
Scanner sc = new Scanner (System.in);
String choice = sc.nextLine();

if (choice.equalsIgnoreCase("Yes")) {
OpenAccount obj = new OpenAccount();
obj.createAccount();
}
if (choice.endsWith("No")) {
BankAccount obj1=new BankAccount();
obj1.showMenu();
}

}

}
class OpenAccount {
String name;
int accountNum;
String accountType;
String dob;
String bank;

void createAccount() {
Scanner sc = new Scanner(System.in);
System.out.println("In Which Bank Do You Wanted To Open An Account : 1.SBI 2.ICICI 3.UNION");
int choiceBank = sc.nextInt();
if (choiceBank == 1) {
bank = "SBI";
}
if (choiceBank == 1) {
bank = "ICICI";
}
if (choiceBank == 1) {
bank = "UNION";
}
System.out.println("Please Enter Your Good Name:");
sc.nextLine();
name = sc.nextLine();

System.out.println("Please Enter Your Date of Birth:");
dob=sc.nextLine();

System.out.println("What Type of Account Do You Wanted to Open: 1.Saving 2.Current");
int choice = sc.nextInt();
if (choice == 1) {
accountType = "Saving";
}
if (choice == 1) {
accountType = "Current";
}

System.out.println("Your accoun has been opened with following deatails");
System.out.println("Bank:"+bank);
System.out.println("Name:"+name);
System.out.println("DOB:"+dob);
System.out.println("Account Type:"+accountType);
System.out.println("Account Number:"+Math.random());

System.out.println("\n");


BankAccount obj1 = new BankAccount();
obj1.showMenu();
sc.close();
}

}
class BankAccount{
int balance;
int previousTransaction;
String cutomerName;
String cutomerId;
String accountType;
double totalInterest;

void calculateInterest(double balance) {
System.out.println("What Type of Account Do You Wanted to Open: 1.Saving 2.Current");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();

if (choice ==1) {
accountType = "Saving";
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);

}
}
void deposit (int amount) {
if (amount != 0);{
balance = balance + amount;
System.out.println("Balance after deposit:"+ balance);
previousTransaction =amount;
}


}
void withdraw (int amount) {
if (amount != 0);{
balance = balance - amount;
System.out.println("Balance after withdraw:"+balance);
previousTransaction =-amount;

}
}
void getPreviousTransction() {
FileOutputStream out;
PrintStream p;

try {
out = new FileOutputStream("C:\\Users\\hp\\eclipse-workspace\\Final_RBI_Project2\\src\\BankPackage\\RBI.java");
p = new PrintStream(out);

if (previousTransaction > 0) {
p.append("Deposited:"+ previousTransaction);
System.out.println("Deposited:"+ previousTransaction);

}else if (previousTransaction < 0) {
p.append("Withdraw:"+ previousTransaction);
System.out.println("Withdraw:"+ Math.absExact(previousTransaction));
}else {
System.out.println("No Transaction occured");
}
p.close();
}catch (Exception e) {
System.out.println("Error in printing the date"+ e);
}

}
void showMenu() {
char option = '\0';
Scanner scanner = 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 an Option");
System.out.println("****************************************");
option = scanner.next().charAt(0);
System.out.println("\n");


switch(option) {
case 'A':
System.out.println("-----------------------------------------------");
System.out.println("Balance ="+ balance);
System.out.println("\n");
break;

case 'B':
System.out.println("-----------------------------------------------");
System.out.println("Enter an amount to deposit:");
int amount = scanner.nextInt();
deposit(amount);
System.out.println("\n");
break;

case 'c':
System.out.println("-----------------------------------------------");
System.out.println("Enter an amount to Withdraw:");
int amount2= scanner.nextInt();
deposit(amount2);
System.out.println("\n");
break;


case 'D':
System.out.println("-----------------------------------------------");
getPreviousTransction();
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("Entered invalid option!. Please Enter Again");
break;

}
}
while(option != 'F');
System.out.println("Thank You for Using Our Servises");
scanner.close();
}
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.