Challenge

Project 2

import java.util.*;
import java.io.*;
public class Banking {
public static void main(String[] args) {
System.out.print("Welcome to Banking Management System\n");
Scanner in = new Scanner(System.in);
// TODO Auto-generated method stub
int loops=2;
while(loops>0) {
System.out.println("\nWant to open an account : Y/N");
String choice = in.next();
if(choice.equals("Y")) {
System.out.println("Enter the name of bank:");
String bname = in.next();
System.out.println("Personal Details");
Customer c = new Customer();
Account ac =new Account();
c.customer_details();
System.out.println("Account Details");
ac.account_details();
if(!(c.name.isEmpty()) || !(c.dob.isEmpty()) | !(ac.type.isEmpty()) || !(ac.accnum.isEmpty())) {
System.out.println("Account Created Successfully in " + bname + " bank and Account number is:"+ac.accnum);
RBI r = new RBI();
r.rbi();
}

}
else {
System.out.println("Thank You \n Bye \n Exiting........");
}
}
}
}
class Customer {
String name,dob;
Scanner sc= new Scanner(System.in);
public void customer_details() {

System.out.println("Enter Name :");
name=sc.next();
System.out.println("Enter Date of Birth (dd-mm-yyyy) :");
dob=sc.next();
}
}

class Account{
String type,accnum;
Scanner s = new Scanner(System.in);
public void account_details() {
System.out.println("Enter type of account:(saving/current) :");
type=s.next();
System.out.println("Enter Account Number");
accnum=s.next();
}
}
class RBI {
public void rbi() {
// TODO Auto-generated constructor stub
Scanner sc = new Scanner(System.in);
int balance=0;
int c=4;
String mini="";
while(c>0) {
System.out.println("1.Deposit Money");
System.out.println("2.Withdraw Money");
System.out.println("3.View Balance");
System.out.println("4.Calculate Interest");
System.out.println("5.Exit");
System.out.println("Enter your choice:");
int ch = sc.nextInt();
if(ch==1) {
System.out.println("Enter amount to deposit:");
int depmoney = sc.nextInt();
balance+=depmoney;
System.out.println("Amount deposited successfully");
System.out.println("Want to print Mini statement:y/n");
mini=sc.next();
if(mini.equals("y")) {
File file = new File("Statements.txt");
try {
file.createNewFile();
boolean exists = file.exists();
if(exists==true) {
file.setWritable(true);
try(BufferedWriter bw = new BufferedWriter(new FileWriter(file,true))) {
bw.append("Amount Deposited: " + depmoney+"\n Current Balance:"+balance);
bw.newLine();

}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
catch(IOException e) {
e.printStackTrace();
}
}
else {
continue;
}
}
else if(ch==2) {
System.out.println("Enter money to withdraw");
int withdrawmoney = sc.nextInt();
if(balance<2000) {
System.out.println("Cannot Withdraw money less than 2000");
}
else {
System.out.println("Withdrawl successfully");
balance-=withdrawmoney;
if(mini.equals("y")) {
File file = new File("Statements.txt");
try {
file.createNewFile();
boolean exists = file.exists();
if(exists==true) {
file.setWritable(true);
try(BufferedWriter bw = new BufferedWriter(new FileWriter(file,true))) {
bw.append("Withdrawl Money: " + withdrawmoney+"\n Current Balance:"+balance);
bw.newLine();

}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
catch(IOException e) {
e.printStackTrace();
}
}
else {
continue;
}
}
}
else if(ch==3) {
System.out.println("Balance:"+balance);
}
else if(ch==4) {
System.out.println("Calculate Interest");
int interestrates=5;
System.out.println("For how many years you want to calculate?");
int years =sc.nextInt();
int a=balance * (1 + interestrates*years);
System.out.println("Total amount to be paid with interest will be " + a + " for " + years + " years for a annual rate of " +interestrates+"%");
}
else if(ch==5) {
System.out.println("Thankyou \n Bye");
break;
}
else {
System.out.println("Invalid choice");
break;
}
}
}
}

OUTPUT:

Welcome to Banking Management System

Want to open an account : Y/N
Y
Enter the name of bank:
SBI
Personal Details
Enter Name :
Abrar
Enter Date of Birth (dd-mm-yyyy) :
22-09-2000
Account Details
Enter type of account:(saving/current) :
savings
Enter Account Number
4321
Account Created Successfully in SBI bank and Account number is:4321
1.Deposit Money
2.Withdraw Money
3.View Balance
4.Calculate Interest
5.Exit
Enter your choice:
1
Enter amount to deposit:
3000
Amount deposited successfully
Want to print Mini statement:y/n
y
1.Deposit Money
2.Withdraw Money
3.View Balance
4.Calculate Interest
5.Exit
Enter your choice:
2
Enter money to withdraw
2002
Withdrawl successfully
1.Deposit Money
2.Withdraw Money
3.View Balance
4.Calculate Interest
5.Exit
Enter your choice:
3
Balance:998
1.Deposit Money
2.Withdraw Money
3.View Balance
4.Calculate Interest
5.Exit
Enter your choice:
4
Calculate Interest
For how many years you want to calculate?
2
Total amount to be paid with interest will be 10978 for 2 years for a annual rate of 5%
1.Deposit Money
2.Withdraw Money
3.View Balance
4.Calculate Interest
5.Exit
Enter your choice:
5
Thankyou
Bye

Want to open an account : Y/N
Y
Enter the name of bank:

File:statements.txt

Amount Deposited: 5000
Current Balance:5000
Amount Deposited: 3000
Current Balance:8000
Amount Deposited: 3000
Current Balance:3000
Withdrawl Money: 2002
Current Balance:998

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.