diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..9a19b69 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..11e9fe6 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,11 @@ +# Default ignored files +/shelf/ +/workspace.xml +<<<<<<< HEAD +======= +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +>>>>>>> a9d9c896ec88f3496cc4bbddf352aacf9249c315 diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0319d5d --- /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..528cb1e --- /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/ATM-Machine-Java.iml b/ATM-Machine-Java.iml new file mode 100644 index 0000000..e921c77 --- /dev/null +++ b/ATM-Machine-Java.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ATM/Account.java b/ATM/Account.java index c52e03d..c2adc9f 100644 --- a/ATM/Account.java +++ b/ATM/Account.java @@ -1,4 +1,10 @@ +import java.io.FileWriter; +import java.io.PrintWriter; +import java.text.DateFormat; import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; import java.util.InputMismatchException; import java.util.Scanner; @@ -6,8 +12,13 @@ public class Account { // variables private int customerNumber; private int pinNumber; - private double checkingBalance = 0; + private double checkingBalance; private double savingBalance = 0; + private FileWriter fileWriter; + private PrintWriter printWriter; + Date date = Calendar.getInstance().getTime(); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + String strDate = dateFormat.format(date); Scanner input = new Scanner(System.in); DecimalFormat moneyFormat = new DecimalFormat("'$'###,##0.00"); @@ -26,7 +37,12 @@ public Account(int customerNumber, int pinNumber, double checkingBalance, double this.checkingBalance = checkingBalance; this.savingBalance = savingBalance; } +//Add the ability to show statement of all your account balances + public String getStatement(){ + return "Your checking balance is: "+ getCheckingBalance()+"\n" + +"Your saving balance is: "+ getSavingBalance(); + } public int setCustomerNumber(int customerNumber) { this.customerNumber = customerNumber; return customerNumber; @@ -83,7 +99,7 @@ public void calcSavingTransfer(double amount) { checkingBalance = checkingBalance + amount; } - public void getCheckingWithdrawInput() { + public void getCheckingWithdrawInput(PrintWriter log) { boolean end = false; while (!end) { try { @@ -93,6 +109,9 @@ public void getCheckingWithdrawInput() { if ((checkingBalance - amount) >= 0 && amount >= 0) { calcCheckingWithdraw(amount); System.out.println("\nCurrent Checkings Account Balance: " + moneyFormat.format(checkingBalance)); + try { + log.println(""+strDate+" Account "+customerNumber+" has withdrawn $" + amount + " from Checking Account."); + } catch (Exception e){} end = true; } else { System.out.println("\nBalance Cannot be Negative."); @@ -104,8 +123,9 @@ public void getCheckingWithdrawInput() { } } - public void getsavingWithdrawInput() { + public void getsavingWithdrawInput(PrintWriter log) { boolean end = false; + while (!end) { try { System.out.println("\nCurrent Savings Account Balance: " + moneyFormat.format(savingBalance)); @@ -114,6 +134,10 @@ public void getsavingWithdrawInput() { if ((savingBalance - amount) >= 0 && amount >= 0) { calcSavingWithdraw(amount); System.out.println("\nCurrent Savings Account Balance: " + moneyFormat.format(savingBalance)); + try { + log.println(""+strDate+" Account "+customerNumber+" has withdrawn $" + amount + " from Savings Account."); + } catch (Exception e){} + end = true; } else { System.out.println("\nBalance Cannot Be Negative."); @@ -125,7 +149,7 @@ public void getsavingWithdrawInput() { } } - public void getCheckingDepositInput() { + public void getCheckingDepositInput(PrintWriter log) { boolean end = false; while (!end) { try { @@ -135,6 +159,10 @@ public void getCheckingDepositInput() { if ((checkingBalance + amount) >= 0 && amount >= 0) { calcCheckingDeposit(amount); System.out.println("\nCurrent Checkings Account Balance: " + moneyFormat.format(checkingBalance)); + try { + log.println(""+strDate+" Account "+customerNumber+" has deposit $" + amount + " from Checking Account."); + } catch (Exception e){} + end = true; } else { System.out.println("\nBalance Cannot Be Negative."); @@ -146,7 +174,7 @@ public void getCheckingDepositInput() { } } - public void getSavingDepositInput() { + public void getSavingDepositInput(PrintWriter log) { boolean end = false; while (!end) { try { @@ -157,6 +185,10 @@ public void getSavingDepositInput() { if ((savingBalance + amount) >= 0 && amount >= 0) { calcSavingDeposit(amount); System.out.println("\nCurrent Savings Account Balance: " + moneyFormat.format(savingBalance)); + try { + log.println(""+strDate+" Account "+customerNumber+" has deposit $" + amount + " from Saving Account."); + } catch (Exception e){} + end = true; } else { System.out.println("\nBalance Cannot Be Negative."); @@ -168,7 +200,7 @@ public void getSavingDepositInput() { } } - public void getTransferInput(String accType) { + public void getTransferInput(String accType,PrintWriter log) { boolean end = false; while (!end) { try { @@ -188,6 +220,10 @@ public void getTransferInput(String accType) { System.out.println("\nCurrent Savings Account Balance: " + moneyFormat.format(savingBalance)); System.out.println( "\nCurrent Checkings Account Balance: " + moneyFormat.format(checkingBalance)); + try { + log.println(""+strDate+" Account "+customerNumber+" has transfer $" + amount + " from Checking Account."); + } catch (Exception e){} + end = true; } else { System.out.println("\nBalance Cannot Be Negative."); diff --git a/ATM/OptionMenu.java b/ATM/OptionMenu.java index ed1aba4..0080e0f 100644 --- a/ATM/OptionMenu.java +++ b/ATM/OptionMenu.java @@ -1,20 +1,28 @@ +import java.io.BufferedWriter; +import java.io.FileWriter; import java.io.IOException; +import java.io.PrintWriter; +import java.text.DateFormat; import java.text.DecimalFormat; -import java.util.HashMap; -import java.util.InputMismatchException; -import java.util.Iterator; -import java.util.Map; -import java.util.Scanner; +import java.text.SimpleDateFormat; +import java.util.*; public class OptionMenu { Scanner menuInput = new Scanner(System.in); DecimalFormat moneyFormat = new DecimalFormat("'$'###,##0.00"); + ArrayList users = new ArrayList<>(); + FileWriter logWriter; + PrintWriter logFile; + + String strDate; + HashMap data = new HashMap(); public void getLogin() throws IOException { boolean end = false; int customerNumber = 0; int pinNumber = 0; + Account acc; while (!end) { try { System.out.print("\nEnter your customer number: "); @@ -24,9 +32,11 @@ public void getLogin() throws IOException { Iterator it = data.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); - Account acc = (Account) pair.getValue(); + acc = (Account) pair.getValue(); + if (data.containsKey(customerNumber) && pinNumber == acc.getPinNumber()) { getAccountType(acc); + end = true; break; } @@ -47,23 +57,36 @@ public void getAccountType(Account acc) { System.out.println("\nSelect the account you want to access: "); System.out.println(" Type 1 - Checkings Account"); System.out.println(" Type 2 - Savings Account"); - System.out.println(" Type 3 - Exit"); + System.out.println(" Type 3 - Show Statement"); + System.out.println(" Type 4 - Log Out"); + System.out.println(" Type 5 - Exit"); System.out.print("\nChoice: "); int selection = menuInput.nextInt(); switch (selection) { - case 1: - getChecking(acc); - break; - case 2: - getSaving(acc); - break; - case 3: - end = true; - break; - default: - System.out.println("\nInvalid Choice."); + case 1: + getChecking(acc); + break; + case 2: + getSaving(acc); + break; + case 3: + showStatement(acc); + break; + case 4: + try{ + getLogin(); + }catch (IOException e){ + + } + break; + case 5: + allAccount(); + end = true; + break; + default: + System.out.println("\nInvalid Choice."); } } catch (InputMismatchException e) { System.out.println("\nInvalid Choice."); @@ -87,24 +110,24 @@ public void getChecking(Account acc) { int selection = menuInput.nextInt(); switch (selection) { - case 1: - System.out.println("\nCheckings Account Balance: " + moneyFormat.format(acc.getCheckingBalance())); - break; - case 2: - acc.getCheckingWithdrawInput(); - break; - case 3: - acc.getCheckingDepositInput(); - break; - - case 4: - acc.getTransferInput("Checkings"); - break; - case 5: - end = true; - break; - default: - System.out.println("\nInvalid Choice."); + case 1: + System.out.println("\nCheckings Account Balance: " + moneyFormat.format(acc.getCheckingBalance())); + break; + case 2: + acc.getCheckingWithdrawInput(logFile); + break; + case 3: + acc.getCheckingDepositInput(logFile); + break; + + case 4: + acc.getTransferInput("Checkings", logFile); + break; + case 5: + end = true; + break; + default: + System.out.println("\nInvalid Choice."); } } catch (InputMismatchException e) { System.out.println("\nInvalid Choice."); @@ -126,23 +149,23 @@ public void getSaving(Account acc) { System.out.print("Choice: "); int selection = menuInput.nextInt(); switch (selection) { - case 1: - System.out.println("\nSavings Account Balance: " + moneyFormat.format(acc.getSavingBalance())); - break; - case 2: - acc.getsavingWithdrawInput(); - break; - case 3: - acc.getSavingDepositInput(); - break; - case 4: - acc.getTransferInput("Savings"); - break; - case 5: - end = true; - break; - default: - System.out.println("\nInvalid Choice."); + case 1: + System.out.println("\nSavings Account Balance: " + moneyFormat.format(acc.getSavingBalance())); + break; + case 2: + acc.getsavingWithdrawInput(logFile); + break; + case 3: + acc.getSavingDepositInput(logFile); + break; + case 4: + acc.getTransferInput("Savings", logFile); + break; + case 5: + end = true; + break; + default: + System.out.println("\nInvalid Choice."); } } catch (InputMismatchException e) { System.out.println("\nInvalid Choice."); @@ -154,6 +177,7 @@ public void getSaving(Account acc) { public void createAccount() throws IOException { int cst_no = 0; boolean end = false; + Account newAcc; while (!end) { try { System.out.println("\nEnter your customer number "); @@ -175,15 +199,34 @@ public void createAccount() throws IOException { } System.out.println("\nEnter PIN to be registered"); int pin = menuInput.nextInt(); - data.put(cst_no, new Account(cst_no, pin)); + newAcc = new Account(cst_no, pin); + data.put(cst_no, newAcc); + users.add(newAcc); System.out.println("\nYour new account has been successfuly registered!"); System.out.println("\nRedirecting to login............."); + try{ + logFile.println(""+strDate+" New Account "+newAcc.getCustomerNumber()+" has been successfully registered."); + }catch(Exception e){} getLogin(); } public void mainMenu() throws IOException { - data.put(952141, new Account(952141, 191904, 1000, 5000)); - data.put(123, new Account(123, 123, 20000, 50000)); + + logWriter = new FileWriter("./log.txt"); + logFile = new PrintWriter(logWriter); + + Date date = Calendar.getInstance().getTime(); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + strDate = dateFormat.format(date); + + Account temp = new Account(952141, 191904, 1000, 5000); + data.put(952141, temp); + users.add(temp); + + temp = new Account(123, 123, 20000, 50000); + data.put(123, temp); + users.add(temp); + boolean end = false; while (!end) { try { @@ -192,16 +235,16 @@ public void mainMenu() throws IOException { System.out.print("\nChoice: "); int choice = menuInput.nextInt(); switch (choice) { - case 1: - getLogin(); - end = true; - break; - case 2: - createAccount(); - end = true; - break; - default: - System.out.println("\nInvalid Choice."); + case 1: + getLogin(); + end = true; + break; + case 2: + createAccount(); + end = true; + break; + default: + System.out.println("\nInvalid Choice."); } } catch (InputMismatchException e) { System.out.println("\nInvalid Choice."); @@ -212,4 +255,48 @@ public void mainMenu() throws IOException { menuInput.close(); System.exit(0); } + + public void showStatement(Account acc) { + boolean end = false; + while (!end) { + try { + System.out.println(acc.getStatement()); + System.out.println(" Type 1 - Main menu"); + System.out.println(" Type 2 - Exit"); + System.out.print("\nChoice: "); + + int selection = menuInput.nextInt(); + + switch (selection) { + case 1: + getAccountType(acc); + break; + case 2: + //end = true; + allAccount(); + System.exit(0); + break; + default: + System.out.println("\nInvalid Choice."); + } + } catch (InputMismatchException e) { + System.out.println("\nInvalid Choice."); + menuInput.next(); + } + } + } + public void allAccount(){ + try { + FileWriter fileWriter = new FileWriter("./userInfo.txt"); + PrintWriter printWriter = new PrintWriter(fileWriter); + for (int i = 0; i < users.size(); i++) { + printWriter.println(users.get(i).getCustomerNumber()+",\t\t\t"+users.get(i).getCheckingBalance()+",\t\t\t"+users.get(i).getSavingBalance()); + + } + printWriter.close(); + logFile.close(); + }catch (Exception e){ + + } + } } diff --git a/log.txt b/log.txt new file mode 100644 index 0000000..64b0a92 --- /dev/null +++ b/log.txt @@ -0,0 +1,2 @@ +2022-11-27 01:39:40 Account 123 has deposit $10000.0 from Checking Account. +2022-11-27 01:39:40 Account 123 has transfer $2000.0 from Checking Account. diff --git a/out/.DS_Store b/out/.DS_Store new file mode 100644 index 0000000..409ad9b Binary files /dev/null and b/out/.DS_Store differ diff --git a/out/production/.DS_Store b/out/production/.DS_Store new file mode 100644 index 0000000..d11e60c Binary files /dev/null and b/out/production/.DS_Store differ diff --git a/userInfo.txt b/userInfo.txt new file mode 100644 index 0000000..d80bad5 --- /dev/null +++ b/userInfo.txt @@ -0,0 +1,2 @@ +952141, 1000.0, 5000.0 +123, 28000.0, 52000.0