You are on page 1of 14

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this
template
*/
package bank;

import java.io.*;
import java.util.ArrayList;
public class Bank {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
BufferedReader coms = new BufferedReader(new
InputStreamReader(System.in));
int userType;
File myFile= new File("dbBank.txt");

if(myFile.createNewFile())
{
System.out.println("File Created: " +myFile.getName());
}
else
{

}
// getting user type
System.out.println("*****BANK*****");
System.out.println("GOOD DAY!");
System.out.println("1. New User");
System.out.println("2. Existing User");
System.out.println("****************************");
System.out.print ("Command: ");
userType = Integer.parseInt(coms.readLine());
System.out.println(" ");
// end

switch(userType)
{
case 1:
createUser();
break;
case 2:
toLogin();
break;
default:
System.out.println("*****Error!*****");
System.out.println("Services has been discontinue");
System.out.println("***************************");
System.out.println("Invalid Input");
System.exit(0);
break;
}
}
catch(Exception e)
{

}
}
static void toLogin()
{
try
{
BufferedReader coms = new BufferedReader(new InputStreamReader(System.in));
FileReader fr = new FileReader("dbBank.txt");
BufferedReader br = new BufferedReader(fr);
String line;
String currAccno = "" , currPinno ="" , currFname = "", currMname = "",
currLname ="" ,currVal = "";
boolean found = false;

ArrayList<String> tempArray = new ArrayList<>();

System.out.println("*****SIGN IN*****");
System.out.print("Please Enter your 8 Digit Account no: ");
String userAccNo = coms.readLine();
while((line = br.readLine())!=null)
{
String[] split = line.split("!");
String accNumber = split[0];

if(userAccNo.equals(accNumber))
{
currAccno = split[0];
currPinno = split[1];
currFname = split[2];
currMname = split[3];
currLname = split[4];
currVal = split[5];
found = true;
}
else
{
tempArray.add(line);
}
}
br.close();

FileWriter fw = new FileWriter("dbBank.txt",true);

if(found==true)
{
String Fullname = currFname+" "+currMname+". "+currLname;
for(int x = 1; x<=3;x++)
{

System.out.print("PIN no: ");


String userPinno = coms.readLine();
System.out.println("");
if(userPinno.equals(currPinno))
{

int services;

System.out.println("SIGN IN SUCCESS");
System.out.println("GOOD DAY SIR!: " + Fullname);
System.out.println("Account Number: " + currAccno);
System.out.println("**************************");
System.out.println("*****SERVICES*****");
System.out.println("1. Balance");
System.out.println("2. Withdraw");
System.out.println("3. Deposit");
System.out.println("4. Trasfer Fund");
System.out.println("5. Payments");
System.out.println("6. Change Pin");
System.out.println("7. Sign Out");
System.out.println("*********************");
System.out.print("Command: ");
services = Integer.parseInt(coms.readLine());
System.out.println(" ");

double bal = Double.parseDouble(currVal);

switch(services)
{
case 1:
System.out.println("*****BALANCE INQUIRY*****");
System.out.println("Current Balance: " + bal);
System.out.println(" ");
System.out.println("OHH DIBA!? YAMAN MO NA!!");
currVal = Double.toString(bal);
editTxtFile(tempArray);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
case 2:
double witamt;
System.out.println("*****WITHDRAW*****");
System.out.println("Please enter the amount");

System.out.println("******************************");
System.out.print("Amount: ");
witamt = Double.parseDouble(coms.readLine());
System.out.println(" ");
if (bal < witamt)
{
System.out.println("*****STOP!*****");
System.out.println("The sevice has been
Discontinue");

System.out.println("******************************");
System.out.println("Not Enough Balance");

}
else
{
bal = bal - witamt;
System.out.println("*****SUCCESS*****");
System.out.println("You withdrawn the amount of
PHP " + witamt);

System.out.println("**********************************");
System.out.println("New Balance: " + bal);
}
System.out.println(" ");
System.out.println("MAGANDANG BUHAY MARAMING SALAMA
PO!");
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();

break;
case 3:

double depamt;
System.out.println("*****DEPOSIT*****");
System.out.println("Please enter the amount");

System.out.println("*************************************");
System.out.print("Amount: ");
depamt = Double.parseDouble(coms.readLine());
System.out.println(" ");

bal = bal + depamt;


System.out.println("*****SUCCESS*****");
System.out.println("You deposited the amount of PHP
" + depamt);

System.out.println("**********************************");
System.out.println("New Balance: " + bal);

System.out.println(" ");
System.out.println("MAGANDANG BUHAY MARAMING
SALAMAT PO!");
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
case 4:

String othaccno;
double traamt;
System.out.println("*****TRANSFER FUND*****");
System.out.println("Enter your recepient's Account
Number");
System.out.println("And their Transfer Amount");

System.out.println("************************************");
System.out.print ("Account Number: ");
othaccno = coms.readLine();
System.out.print ("Amount: ");
traamt = Double.parseDouble(coms.readLine());
System.out.println(" ");
if (bal < traamt)
{
System.out.println("*****STOP!*****");
System.out.println("Services has been
Discontinue");

System.out.println("*********************************");
System.out.println("Not Enough Balance");

}
else
{
bal = bal - traamt;
System.out.println("*****SUCCESS*****");
System.out.println("You transfered the amount
of PHP " + traamt);

System.out.println("***********************************");
System.out.println("To: " + othaccno);
System.out.println("From: " + currAccno);

System.out.println("**********************************");
System.out.println("New Balance: " + bal);

}
System.out.println(" ");
System.out.println("MAGANDANG BUHAY MARAMING SALAMA
PO!");
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
case 5:
int paycomms;
String compname;
String paypurpose;
double payamt;
System.out.println("*****PAYMENTS*****");
System.out.println("You can pay the following");

System.out.println("*********************************************");
System.out.println("1. Electric Bills");
System.out.println("2. Water Bills");
System.out.println("3. Internet Bills");

System.out.println("**********************************************");
System.out.print("Command: ");
paycomms = Integer.parseInt(coms.readLine());
System.out.println(" ");
switch (paycomms)
{
case 1:

System.out.println("*****ELECTRICITY*****");
System.out.println("Please enter
the company name and amount of payment");
System.out.println("Please enter
the specific amount");

System.out.println("*********************************");
System.out.print("Company: ");
compname = coms.readLine();
System.out.print("Purpose: ");
paypurpose = coms.readLine();
System.out.print("Amount: ");
payamt =
Double.parseDouble(coms.readLine());
System.out.println(" ");
if (bal < payamt)
{
System.out.println("*****STOP!
*****");

System.out.println("*********************************");
System.out.println(" Not Enough
Balance");

}
else
{
bal = bal - payamt;

System.out.println("*****SUCCESS*****");
System.out.println("You paid
the amount of PHP " + payamt + " for electricity");

System.out.println("************************************");
System.out.println("Company: "
+ compname);
System.out.println("Purpose: "
+ paypurpose);
System.out.println("Amount : "
+ payamt);

System.out.println("************************************");
System.out.println("New
Balance: " + bal);
System.out.println("MAGANDANG
BUHAY MARAMING SALAMA PO!");
}
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
case 2:
System.out.println("*****WATER
BILL*****");
System.out.println("Please enter
the company name and amount of payment");
System.out.println("Please enter
the specific amount");

System.out.println("*********************************************");
System.out.print("Company: ");
compname = coms.readLine();
System.out.print("Purpose: ");
paypurpose = coms.readLine();
System.out.print("Amount : ");
payamt =
Double.parseDouble(coms.readLine());
System.out.println(" ");
if (bal < payamt)
{
System.out.println("*****STOP!
*****");
System.out.println("Services
has been Discontinue");

System.out.println("************************************");
System.out.println("Not Enough
Balance");

}
else
{
bal = bal - payamt;
System.out.println("SUCCESS");
System.out.println("You paid
the amount of PHP " + payamt + " for water");

System.out.println("***********************************");
System.out.println("Company: "
+ compname);
System.out.println("Purpose: "
+ paypurpose);
System.out.println("Amount : "
+ payamt);

System.out.println("**************************************");
System.out.println("New
Balance: " + bal);

}
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
case 3:
System.out.println("INTERNET
BILL");
System.out.println("Please enter
the company name and amount of payment");
System.out.println("Please enter
the specific amount");

System.out.println("*****************************************");
System.out.print("Company: ");
compname = coms.readLine();
System.out.print("Purpose: ");
paypurpose = coms.readLine();
System.out.print("Amount: ");
payamt =
Double.parseDouble(coms.readLine());
System.out.println(" ");
if (bal < payamt)
{
System.out.println("*****STOP!
*****");
System.out.println("Services
has been Discontinue");

System.out.println("*****************************************");
System.out.println("Not Enough
Balance");

}
else
{
bal = bal - payamt;

System.out.println("*****SUCCESS!*****");
System.out.println("You paid
the amount of PHP " + payamt + " for internet");

System.out.println("**************************");
System.out.println("Company: "
+ compname);
System.out.println("Purpose: "
+ paypurpose);
System.out.println("Amount : "
+ payamt);

System.out.println("********************************");
System.out.println("New
Balance: " + bal);

}
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
default:
System.out.println("*****STOP!
*****");
System.out.println("Services has
been Discontinue");

System.out.println("***********************************");
System.out.println("Invalid
Input");

}
break;
case 6:
String opinv;
String npinno2;
String nppinv;
System.out.println("*****CHANGE PIN*****");
System.out.println("Please Enter Your Old Pin
no.");
for (int c = 1; c <=3; c++)
{

System.out.println("*******************************");
System.out.print("PIN No.: ");
opinv = coms.readLine();
System.out.println(" ");
if (opinv.equals(currPinno))
{
System.out.println("Please Enter your new
PIN no.");

System.out.println("*******************************");
System.out.print("PIN no.: ");
npinno2 = coms.readLine();
System.out.println(" ");
System.out.println("PIN VERIPICATION");
System.out.println("Please verify your new
PIN no.");

System.out.println("*********************************");
for (int d = 1; d <= 3; d++)
{
System.out.print("PIN no.: ");
nppinv = coms.readLine();
System.out.println(" ");
if (nppinv.equals(npinno2))
{
System.out.println("SUCCESS");
System.out.println("Your PIN No.
has been changed");
System.out.println("MAGANDANG BUHAY
MARAMING SALAMA PO!");
currPinno = nppinv;
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
}
else
{
System.out.println("ERROR!");
System.out.println("Wrong PIN
No.");
System.out.println(" ");
if (d == 3)
{
System.out.println("STOP!");
System.out.println("PIN Change
has been Discontinue");

System.out.println("****************************************");
System.out.println("Attempt
Limit has been Reached");
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
}
else
{
System.out.println ("Please Try
Again");
System.out.println ("Attempts:
" + d+ "/3");
System.out.println (" ");
}
}
}
break;
}
else
{
System.out.println("*****ERROR*****");
System.out.println("Wrong PIN No.");
System.out.println(" ");
if (c == 3)
{
System.out.println("STOP!");
System.out.println("Sign In has been
Discontinue");

System.out.println("***************************************");
System.out.println("Attempt Limit has
been Reached");
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();
break;
}
else
{
System.out.println("Please Try Again");
System.out.println("Attempts: " + c +
"/3");
System.out.println(" ");
}
}
}
break;
case 7:
System.out.println("SIGN OUT");
System.out.println("");
System.out.println("MAGANDANG BUHAY MARAMING SALAMA
PO!");
editTxtFile(tempArray);
currVal = Double.toString(bal);

fw.write(currAccno+"!"+currPinno+"!"+currFname+"!"+currMname.charAt(0)+"!"+currLnam
e+"!"+currVal);
fw.close();

break;
default:
System.out.println("*****ERROR!!!*****");
break;
}
break;

}
else
{
System.out.println("*****ERROR*****");
System.out.println("Wrong PIN No.");
System.out.println(" ");

if (x == 3)
{
System.out.println("*****STOP!*****");
System.out.println("Sign In has been Discontinue");

System.out.println("*************************************");
System.out.println("Invalid PIN Number Attempt Limit
has been Reached");

break;

}
else
{
System.out.println("Please Try Again");
System.out.println("Attempts: " + x + "/3");
System.out.println(" ");
}
}

}
}
else
{
System.out.println("********Account didn't exist!************");
System.out.println("**********Try again later!***************");
System.exit(0);

}
}
catch(Exception e)
{

}
}

static void editTxtFile(ArrayList<String>tempArray)


{
try
{
PrintWriter pr = new PrintWriter("dbBank.txt");
for(String str: tempArray)
{
pr.println(str);
}
pr.close();
}
catch(Exception e)
{

static void createUser()


{
try{
BufferedReader coms = new BufferedReader(new
InputStreamReader(System.in));
String fname;
String mname;
String lname;
long naccno;
int npinno;
int vpin1;
System.out.println("*****SIGN UP*****");
System.out.print ("First Name: ");
fname = coms.readLine();
System.out.print ("Middle Name: ");
mname = coms.readLine();
System.out.print ("Last Name: ");
lname = coms.readLine();
System.out.println (" ");
System.out.println("*****SECURITY*****");
System.out.print ("8 Digits Account No.: ");
naccno = Long.parseLong(coms.readLine());
System.out.print ("6 Digits PIN No.: ");
npinno = Integer.parseInt(coms.readLine());
System.out.println(" ");
System.out.println("PIN VERIFICATION]");
System.out.println("Verify new PIN no.");
System.out.println("*************************************");
for (int a = 1; a<= 3; a++)
{
System.out.print("PIN no.: ");
vpin1 = Integer.parseInt(coms.readLine());
System.out.println (" ");
if (vpin1 == npinno)
{

FileWriter fw = new FileWriter("dbBank.txt",true);


System.out.println("*****SUCCESS*****");
System.out.println("Pin Number Correct!");
System.out.println(" ");
System.out.println("CONFIRMATION");
System.out.println("***************************");

fw.write(naccno+"!"+npinno+"!"+fname+"!"+mname.charAt(0)+"!"+lname+"!"+"0");
fw.write(System.lineSeparator());
System.out.println("************************************");
System.out.println("Your Account has been Created");
System.out.println("MAGANDANG BUHAY MARAMING SALAMA PO!");
fw.close();
break;
}
else
{
System.out.println("*****ERROR*****");
System.out.println("Wrong PIN No.");
System.out.println(" ");
if (a == 3)
{
System.out.println("*****INPUT ERROR*****");
System.out.println("Account Creation has been
Discontinue");

System.out.println("**********************************************");
System.out.println("YOU HAVE REATCHED THE LIMIT");

break;
}
else
{
System.out.println ("*****PLEASE TRY AGAIN*****");
System.out.println ("Attempts: " + a + "/3");
System.out.println (" ");
}
}
}

}
catch(Exception e)
{

You might also like