Вы находитесь на странице: 1из 4

package midtermpt;

import java.util.*;
import java.io.*;
public class MidtermPT{
static String totalForCW;
static String ty;
Scanner sc=new Scanner(System.in);
File folder=new File("G:\\TXT.txt");

public void MainPinNumber(){

try{
FileReader fR=new FileReader(folder);
BufferedReader bR=new BufferedReader(fR);
String a="";
int countTry=3;
System.out.println("Please enter your 6 digits PIN number");
String q=sc.nextLine();
a=bR.readLine();
String data[]=a.split(",");
ty=data[1];
while(!q.equals(data[0])){
countTry-=1;
System.out.println("ERROR PIN NUMBER!!!");
System.out.println(countTry+" try(s) left");
System.out.println("\n\nPlease enter your 6 digits PIN number");
q=sc.nextLine();
if(countTry==1 && !q.equals(data[0])){
System.out.println("\n\nCARD CAPTURED!!!");
System.exit(0);
}}System.out.println("PIN CORRECT!!!");
ChoicesNumber();
bR.close();
}catch(Exception ex){}}

public void YESorNO(){

Scanner sc=new Scanner(System.in);


try{
System.out.println("\nDo you want another transaction?\nType Y for Yes N
for No");
String string1=sc.nextLine();
if(string1.equalsIgnoreCase("y")){
ChoicesNumber();
}else if(string1.equalsIgnoreCase("n")){
System.out.println("\n\nTHANK YOU!!!");
System.exit(0);
}else if(string1.isEmpty()){
throw new NullPointerException();
}else if(string1.matches("[0-9]")){
throw new NumberFormatException();
}else{
throw new InputMismatchException();
}}catch(NullPointerException ex){
System.out.println("Blank Answer!!! \nPlease Type Y for Yes N for
No");
YESorNO();
}catch(NumberFormatException e){
System.out.println("Letters Only!!! \nPlease Type Y for Yes N for No");
YESorNO();
}catch(InputMismatchException e){
System.out.println("Invalid Input!!! \nPlease Type Y for Yes N for
No");
YESorNO();
}}

int num;
public void ChoicesNumber(){
Scanner sc=new Scanner(System.in);
System.out.println("\n\n~~~~~~~~~~~~~~~~~~~~ "+ty+"
~~~~~~~~~~~~~~~~~~~~");
System.out.println("~~~~~~~~~~~~~~~~~~~~ BDO CASH WITHDRAWAL
~~~~~~~~~~~~~~~~~~~~");
System.out.println("Select your command");
System.out.println("(1) Balance Inquiry"+"\n(2) Cash Withdrawal");
System.out.println("(3) Cash Deposit"+"\n(4) Exit");
try{num=sc.nextInt();
if(num==1){
Balance();
}else if(num==2){
Cash();
}else if(num==3){
Deposit();
}else if(num==4){
System.out.println("Exit");
System.exit(0);
}else{
throw new Exception();
}}catch(Exception e){
System.out.println("Invalid Input!!!");
YESorNO();}}

public void Cash(){


File folder=new File("G:\\TXT.txt");
Scanner sc=new Scanner(System.in);
try{
FileReader fR=new FileReader(folder);
BufferedReader bR=new BufferedReader(fR);
String a="";
a=bR.readLine();
String data[]=a.split(",");
String ff1=data[0];
String ff2=data[1];
String ff=data[2];
double convert=Double.parseDouble(ff);
FileWriter fW=new FileWriter(folder);
BufferedWriter bW=new BufferedWriter(fW);
System.out.println("Enter your Cash Withdrawal: ");
double ss=sc.nextDouble();
if(ss < convert){
double total=convert-ss;
String gg=String.valueOf(total);
System.out.println("Waiting for your Cash...\nCash Receive...\nYour total
Balance:\n"+total);
bW.write(ff1+","+ff2+","+gg);
}else if(ss>=convert){
System.out.println("Sorry but you don't have enough of Balance \nYour
current Balance is: "+ff);
bW.write(ff1+","+ff2+","+ff);
}bW.close();
bR.close();
YESorNO();
}catch(Exception e){}
System.out.println("Invalid Input!!!");
YESorNO();
}

public void Deposit(){


File folder=new File("G:\\TXT.txt");
Scanner sc=new Scanner(System.in);
try{
FileReader fR=new FileReader(folder);
BufferedReader bR=new BufferedReader(fR);
String a="";
a=bR.readLine();
String data[]=a.split(",");
String ff1=data[0];
String ff2=data[1];
String ff=data[2];
FileWriter fW=new FileWriter(folder);
BufferedWriter bW=new BufferedWriter(fW);
System.out.println("Enter your Cash Deposit: ");
double ss=sc.nextDouble();
double convert=Double.parseDouble(ff);
double total=convert+ss;
String gg=String.valueOf(total);
System.out.println("Waiting for your Cash...\nCash Receive...\nYour total
Balance:\n"+total);
bW.write(ff1+","+ff2+","+gg);

bW.close();
bR.close();
YESorNO();
}catch(Exception e){
System.out.println("Invalid Input!!!");
YESorNO();
}}

public void Balance(){


Scanner sc=new Scanner(System.in);
File folder=new File("G:\\TXT.txt");
try{
FileReader fR=new FileReader(folder);
BufferedReader bR=new BufferedReader(fR);
String a="";
a=bR.readLine();
String data[]=a.split(",");
System.out.println("\n\nYour Total Balance is: "+data[2]);
YESorNO();
bR.close();
}catch(Exception e){}}

public static void main(String[] args) {


MidtermPT thisClass=new MidtermPT();
thisClass.MainPinNumber();
}
}

Вам также может понравиться