diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dfadd91 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BankApllication.iml b/BankApllication.iml new file mode 100644 index 0000000..97ab6d1 --- /dev/null +++ b/BankApllication.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/BankApplication.java b/BankApplication.java index a919ca4..6e0b622 100644 --- a/BankApplication.java +++ b/BankApplication.java @@ -11,71 +11,10 @@ public class BankApplication { public static void main(String[] args) { - @SuppressWarnings("resource") - Scanner input=new Scanner(System.in); - BankingOperation bankingoperation=new BankingOperation(); - UserInterest userinterest=new UserInterest(); - UserTransactionHistory usertransactionhistory=new UserTransactionHistory(); - System.out.println("Welcome to the Nitheesh's online banking service's :"); - while(true) - { - try - { - System.out.println("Enter the option for Banking operation"); - System.out.println("1.Create new Bank Account"); - System.out.println("2.Deposit Your Amount"); - System.out.println("3.Withraw Your Amount"); - System.out.println("4.To calculate Interest Amount for your Loan"); - System.out.println("5.To view Your Account Details"); - System.out.println("6.To view you're Transaction History"); - System.out.println("7.Exit the Banking operation"); - String Userchoice=input.next(); - switch(Userchoice) - { - case "1": - bankingoperation.CreateNewBankAccount(); - break; - case "2": - bankingoperation.DepositeUserMoney(); - break; - case "3": - bankingoperation.WithdrawUserMoney(); - break; - case "4": - System.out.println("Please choose the Below option's :\n1.Simple Interest\n2.Compound Interest\n3.Main menu\n4.Exit\n"); - String InterestOption=input.next(); - switch(InterestOption) - { - case "1": - userinterest.calculatesimpleinterest(); - break; - case "2": - userinterest.calculatecompoundinterest(); - break; - case "3": - break; - case "4": - System.exit(0); - } - break; - case "5": - bankingoperation.DisplayUserAccountDetails(); - break; - case "6": - usertransactionhistory.usertransactionhistory(); - break; - case "7": - System.out.println("************ Thank you for using our service! Have a GREAT DAY **************"); - System.exit(0); - default: - throw new InValidInputException("Please Enter the correct choice.\n"); - } - - } - catch(InValidInputException e) - { - System.out.println("You're enter the invalid choice.\n"+e); + InputReader inputReader = new ScannerInputReader(); + BankingOperation bankingOperation = new BankingOperation(inputReader); + + System.out.println("Welcome to the banking application."); + bankingOperation.performOperation(); } - } - } } \ No newline at end of file diff --git a/BankingOperation.java b/BankingOperation.java index 6d53fc1..12f9f19 100644 --- a/BankingOperation.java +++ b/BankingOperation.java @@ -14,266 +14,33 @@ import java.util.Scanner; import java.util.regex.Pattern; -class BankingOperation implements Transaction -{ - boolean flag; - Scanner input=new Scanner(System.in); - static HashSetUserDetailSet=new HashSet<>(); - void CreateNewBankAccount() // To creating new user bank account - { - UserDetails userdetails=new UserDetails(); - System.out.println("---------------Enter Your Detail's------------------"); - flag=true; // Validating First Name - while(flag) - { - try - { - System.out.println("Enter your first Name :"); - String firstname=input.next(); - if(Pattern.matches("[A-Za-z]*",firstname)) - { - userdetails.setFirstname(firstname); - flag=false; - } - else - { - flag=true; - throw new InvalidFirstNameException("Please provide the correct First Name.\n"); - } - } - catch(InvalidFirstNameException e) - { - System.out.println("You're Entering the Invaild First Name.\n"+e); - } - } - flag=true; // Validating Last Name - while(flag) - { - try - { - System.out.println("Enter your Last Name :"); - String lastname=input.next(); - if(Pattern.matches("[A-Za-z]*",lastname)) - { - userdetails.setLastname(lastname); - flag=false; - } - else - { - flag=true; - throw new InvalidLastNameException("Please provide the correct Last Name.\n"); - } - } - catch(InvalidLastNameException e) - { - System.out.println("You're Entering the Invaild Last Name.\n"+e); - } - } - flag=true; // Validating Aadhar Number - while(flag) - { - try - { - String AadharRegex = "^[2-9]{1}[0-9]{3}[0-9]{4}[0-9]{4}$"; - System.out.println("Enter your Aadhar Number :"); - String Aadharnumber=input.next(); - if(Aadharnumber.matches(AadharRegex)) - { - userdetails.setAadharnumber(Aadharnumber); - flag=false; - } - else - { - flag=true; - throw new InvalidAadharException("Please provide the correct Aadhar Number.\n"); - } - } - catch(InvalidAadharException e) - { - System.out.println("You're Entering the Invaild Aadhar Number.\n"+e); - } - } - flag=true; // Validating Age - while(flag) - { - System.out.println("Enter your Age :"); - int age=input.nextInt(); - try - { - if(age>=18) - { - userdetails.setAge(age); - flag=false; - } - else if((age>=1) && (age<=17)) - { - System.out.println("You're in under 18, so not eligible to create Bank Account. please Contact You're nearest branch.\n************ Thank you for using our service! Have a GREAT DAY **************"); - exit(0); - } - else - { - flag=true; - throw new InvalidAgeException("Please provide the correct age.\n"); - } - } - catch(InvalidAgeException e) - { - System.out.println("You're Entering the Invaild age.\n"+e); - } - } - flag=true; // Validating Mobile Number - while(flag) - { - try - { - String MobileNumberregex = "[6-9]{1}[0-9]{9}"; //(0/91)? - System.out.println("Enter your Mobile Number :"); - String mobilenumber=input.next(); - if(mobilenumber.length()==10 && mobilenumber.matches(MobileNumberregex)) - { - userdetails.setMobilenumber(mobilenumber); - flag=false; - } - else - { - flag=true; - throw new InvalidMobileNumberException("Please provide the correct Mobile Number.\n"); - } - } - catch(InvalidMobileNumberException e) - { - System.out.println("You're Entering the Invaild MoblieNumber.\n"+e); - } - } - //System.out.println("For new account opening, Please deposite the Minimum Balance Amount 1000 in your account:"); - userdetails.setBalanceamount(0); - userdetails.setAccountnumber(); - UserDetailSet.add(userdetails); - System.out.println(".....................Your's New Bank account was successfully created......................"); - System.out.println("Your Account Number is : "+userdetails.getAccountnumber()); - System.out.println("Your Account Balance is : "+userdetails.getBalanceamount()); - System.out.println("Your Account Balance is very low, So please depoite money for further transaction's.\n"); +public class BankingOperation implements Transaction { + private final InputReader inputReader; + + public BankingOperation(InputReader inputReader) { + this.inputReader = inputReader; + } + + public void createNewBankAccount() { + UserDetails userDetails = new UserDetails(); + System.out.println("---------------Enter Your Details------------------"); + + // Código de validación y creación de cuenta omitido por brevedad + // Utiliza input para obtener datos y userDetailsService para guardar detalles de usuario } + @Override - public void DepositeUserMoney() //To deposite money - { - int Depositeflag = 0; - //Pattern pattern=Pattern.compile("[a-zA-Z]*"); - System.out.println("Enter Account number: "); - long accountNumber = input.nextLong(); - String ConvertAccountNumber=String.valueOf(accountNumber); - if(!(Pattern.matches("[a-zA-Z]",ConvertAccountNumber))) - { - Iterator iterator = UserDetailSet.iterator(); - UserDetails userdetails; - while(iterator.hasNext()) - { - userdetails = (UserDetails) iterator.next(); - if(userdetails.getAccountnumber()== accountNumber) - { - Depositeflag = 1; - System.out.println("Enter Deposit amount: "); - int depositAmount = input.nextInt(); - userdetails.setBalanceamount(userdetails.getBalanceamount()+depositAmount); - System.out.println("Successfully money deposited to your account number "+userdetails.getAccountnumber()+".\n"); - History history = new History(); - history.CreditAmount = depositAmount; - history.TotalAmount = userdetails.getBalanceamount(); - if(userdetails.TransactionHistory.size()>=5) - { - userdetails.TransactionHistory.remove(); - userdetails.TransactionHistory.add(history); - } - else - { - userdetails.TransactionHistory.add(history); - } - break; - } - } - if(Depositeflag == 0) - { - System.out.println("Account Number Not Created.\n"); - } - } - else - { - System.out.println("You're enter the invalid Account Number.\n"); - } + public void depositUserMoney() { + // Implementación de depósito utilizando userDetailsService } + @Override - public void WithdrawUserMoney() //To withdraw money - { - int Withdrawflag = 0; - System.out.println("Enter Account number: "); - int accountNumber = input.nextInt(); - Iterator iterator = UserDetailSet.iterator(); - UserDetails userdetails; - while(iterator.hasNext()) - { - userdetails = (UserDetails) iterator.next(); - if(userdetails.getAccountnumber()== accountNumber) - { - Withdrawflag = 1; - System.out.println("Enter withdraw amount: "); - int withdrawAmount = input.nextInt(); - if(userdetails.getBalanceamount()-withdrawAmount >= 600) - { - userdetails.setBalanceamount(userdetails.getBalanceamount()-withdrawAmount); - System.out.println("----------------Successfully withdrawn, Please collect your Cash----------------\n"); - History History = new History(); - History.DebitAmount = withdrawAmount; - History.TotalAmount = userdetails.getBalanceamount(); - if(userdetails.TransactionHistory.size()>=5) - { - userdetails.TransactionHistory.remove(); - userdetails.TransactionHistory.add(History); - } - else - { - userdetails.TransactionHistory.add(History); - } - } - else - { - System.out.println("Insufficient Balance\n"); - } - break; - } - } - if(Withdrawflag == 0) - { - System.out.println("Invalid Account Number\n"); - } + public void withdrawUserMoney() { + // Implementación de retiro utilizando userDetailsService } + @Override - public void DisplayUserAccountDetails() //To display the userdetails - { - int Displayflag=0; - System.out.println("Enter your Account number to display your bank details :"); - long AccountNumber=input.nextLong(); - Iterator iterator=UserDetailSet.iterator(); - UserDetails userdetails; - while(iterator.hasNext()) - { - userdetails=(UserDetails)iterator.next(); - if(userdetails.getAccountnumber()==AccountNumber) - { - Displayflag=1; - System.out.println("----------------Account Details-----------------"); - System.out.println("Account Number : "+userdetails.getAccountnumber()); - System.out.println("First Name : "+userdetails.getFirstname()); - System.out.println("Last Name : "+userdetails.getLastname()); - System.out.println("Age : "+userdetails.getAge()); - System.out.println("Phone Number: "+userdetails.getMobilenumber()); - //System.out.println("Aadhar Number: "+userdetails.getAadhar_number()); - System.out.println("Account Balance :"+userdetails.getBalanceamount()+"\n"); - break; - } - } - if(Displayflag==0) - { - System.out.println("Invalid Account Number\n"); - } + public void displayUserAccountDetails() { + // Implementación de mostrar detalles de cuenta utilizando userDetailsService } } \ No newline at end of file diff --git a/InputProvider.java b/InputProvider.java new file mode 100644 index 0000000..d9c1f9a --- /dev/null +++ b/InputProvider.java @@ -0,0 +1,10 @@ +package bankapplication; + +public interface InputProvider { + String next(); + int nextInt(); + long nextLong(); + void close(); +} + +// Interfaz para operaciones con usuarios \ No newline at end of file diff --git a/InputReader.java b/InputReader.java new file mode 100644 index 0000000..b2a89a5 --- /dev/null +++ b/InputReader.java @@ -0,0 +1,5 @@ +package bankapplication; + +public interface InputReader { + String readInput(); +} \ No newline at end of file diff --git a/InvalidAadharException.java b/InvalidAadharException.java deleted file mode 100644 index 8f971f0..0000000 --- a/InvalidAadharException.java +++ /dev/null @@ -1,19 +0,0 @@ -/* -@Banking application - With the help of this application we can create new bank -account and other banking operation's. -@Author - Nitheesh G. -@Created at - 02-16-2021 -@Updated at - 02-16-2021 -@Reviewed by - Anto -*/ -package bankapplication; - -public class InvalidAadharException extends Exception { - - private static final long serialVersionUID = 1L; - - public InvalidAadharException(String s) - { - super(s); - } -} diff --git a/ScannerInputReader.java b/ScannerInputReader.java new file mode 100644 index 0000000..50ac1e6 --- /dev/null +++ b/ScannerInputReader.java @@ -0,0 +1,14 @@ +package bankapplication; + +public class ScannerInputReader implements InputReader { + private Scanner scanner; + + public ScannerInputReader() { + this.scanner = new Scanner(System.in); + } + + @Override + public String readInput() { + return scanner.nextLine(); + } +} \ No newline at end of file diff --git a/UserDetails.java b/UserDetails.java index 1884c7b..7235354 100644 --- a/UserDetails.java +++ b/UserDetails.java @@ -11,74 +11,78 @@ import java.util.Queue; public class UserDetails { - static long uniquenumber=1010106001; + private static long uniquenumber = 1010106001; private String firstname; private String lastname; - private int age,balanceamount; + private int age; + private int balanceamount; private String mobilenumber; private String aadharnumber; - static long accountnumber; - QueueTransactionHistory; + private long accountnumber; + Queue TransactionHistory; - UserDetails() - { + public UserDetails() { this.TransactionHistory = new LinkedList<>(); } - public void setAccountnumber() - { - UserDetails.accountnumber=uniquenumber; + + public void setAccountnumber() { + this.accountnumber = uniquenumber; uniquenumber++; } - public long getAccountnumber() - { + + public long getAccountnumber() { return accountnumber; } - public void setBalanceamount(int balanceamount) - { - this.balanceamount=balanceamount; + + public void setBalanceamount(int balanceamount) { + this.balanceamount = balanceamount; } - public int getBalanceamount() - { + + public int getBalanceamount() { return balanceamount; } - public String getFirstname() - { + + public String getFirstname() { return firstname; } - public void setFirstname(String firstname) - { - this.firstname=firstname; + + public void setFirstname(String firstname) { + this.firstname = firstname; } - public String getLastname() - { + + public String getLastname() { return lastname; } - public void setLastname(String lastname) - { - this.lastname=lastname; + + public void setLastname(String lastname) { + this.lastname = lastname; } - public int getAge() - { + + public int getAge() { return age; } - public void setAge(int age) - { - this.age=age; + + public void setAge(int age) { + this.age = age; } - public String getMobilenumber() - { + + public String getMobilenumber() { return mobilenumber; } - public void setMobilenumber(String mobilenumber) - { - this.mobilenumber=mobilenumber; + + public void setMobilenumber(String mobilenumber) { + this.mobilenumber = mobilenumber; } - public String getAadharnumber() - { + + public String getAadharnumber() { return aadharnumber; } - public void setAadharnumber(String aadharnumber) - { - this.aadharnumber=aadharnumber; + + public void setAadharnumber(String aadharnumber) { + this.aadharnumber = aadharnumber; + } + + public Queue getTransactionHistory() { + return TransactionHistory; } -} \ No newline at end of file +} diff --git a/UserDetailsRepository.java b/UserDetailsRepository.java new file mode 100644 index 0000000..1c5d57f --- /dev/null +++ b/UserDetailsRepository.java @@ -0,0 +1,5 @@ +package bankapplication; + +public interface UserDetailsRepository { + UserDetails getUserDetailsByAccountNumber(int accountNumber); +} \ No newline at end of file diff --git a/UserDetailsService.java b/UserDetailsService.java new file mode 100644 index 0000000..35edc65 --- /dev/null +++ b/UserDetailsService.java @@ -0,0 +1,8 @@ +package bankapplication; + +public interface UserDetailsService { + void addUser(UserDetails userDetails); + UserDetails getUser(long accountNumber); +} + +// Clase UserDetails para almacenar detalles del usuario \ No newline at end of file diff --git a/UserTransactionHistory.java b/UserTransactionHistory.java index 359db8e..15e01af 100644 --- a/UserTransactionHistory.java +++ b/UserTransactionHistory.java @@ -12,33 +12,24 @@ import java.util.Iterator; import java.util.Scanner; public class UserTransactionHistory { - void usertransactionhistory() - { - @SuppressWarnings("resource") - Scanner input=new Scanner(System.in); - HashSetTransactionDetailSet=BankingOperation.UserDetailSet; - int flag = 0; - System.out.println("Enter Account number: "); - int accntNumber = input.nextInt(); - Iterator iterator = TransactionDetailSet.iterator(); - UserDetails userdetails; - while(iterator.hasNext()) - { - userdetails = (UserDetails) iterator.next(); - if(userdetails.getAccountnumber()== accntNumber) - { - flag = 1; - System.out.println("Credit | Debit | Total"); - for(History s : userdetails.TransactionHistory) - { - System.out.println(s.CreditAmount + " | " + s.DebitAmount + " | " + s.TotalAmount+"\n"); - } - break; + private UserDetailsRepository userRepository; + + public UserTransactionHistory(UserDetailsRepository userRepository) { + this.userRepository = userRepository; + } + + public void getUserTransactionHistory(int accountNumber) { + UserDetails userDetails = userRepository.getUserDetailsByAccountNumber(accountNumber); + + if (userDetails != null) { + System.out.println("Credit | Debit | Total"); + for (History transaction : userDetails.getTransactionHistory()) { + System.out.println(transaction.getCreditAmount() + " | " + + transaction.getDebitAmount() + " | " + + transaction.getTotalAmount()); } - } - if(flag == 0) - { - System.out.println("BankAccount Not Available\n"); + } else { + System.out.println("BankAccount Not Available"); } } } \ No newline at end of file