From a9d9c896ec88f3496cc4bbddf352aacf9249c315 Mon Sep 17 00:00:00 2001 From: Yingjie <52tiffany.yang@gmail.com> Date: Wed, 16 Nov 2022 17:38:03 -0500 Subject: [PATCH 1/2] add NumberGuess --- .idea/.gitignore | 8 ++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ ATM-Machine-Java.iml | 11 +++++++++++ ATM/Account.java | 2 +- 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 ATM-Machine-Java.iml 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..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..88e17c8 100644 --- a/ATM/Account.java +++ b/ATM/Account.java @@ -6,7 +6,7 @@ public class Account { // variables private int customerNumber; private int pinNumber; - private double checkingBalance = 0; + private double checkingBalance; private double savingBalance = 0; Scanner input = new Scanner(System.in); From 8b7d598050bbf38129eab980a8233d6663262fd1 Mon Sep 17 00:00:00 2001 From: Tiffany678 <52tiffany.yang@gmail.comgit config --global user.name Tiffany678git config --global user.email 52tiffany.yang@gmail.com> Date: Sun, 27 Nov 2022 01:41:28 -0500 Subject: [PATCH 2/2] lab completed --- .DS_Store | Bin 0 -> 6148 bytes .idea/.gitignore | 3 + .idea/misc.xml | 6 ++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ ATM-Machine-Java.iml | 11 ++ ATM/Account.java | 46 +++++++- ATM/OptionMenu.java | 219 +++++++++++++++++++++++++++------------ log.txt | 2 + out/.DS_Store | Bin 0 -> 6148 bytes out/production/.DS_Store | Bin 0 -> 6148 bytes userInfo.txt | 2 + 12 files changed, 232 insertions(+), 71 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 ATM-Machine-Java.iml create mode 100644 log.txt create mode 100644 out/.DS_Store create mode 100644 out/production/.DS_Store create mode 100644 userInfo.txt diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9a19b69c0896cd8500e6b2f34c5a1215e4ffba8b GIT binary patch literal 6148 zcmeHKu};H447EvzN-P~2?-%+9X_byhmC6U8Gy_Abs|4M%v9s|%{VFD&eJ-Smx-y_= z$$pm?`!0Dy9E*sqPu)^vAtH0Qp}bp|n%y^_*j+F)pxPe$zRkJEQmRSv4Z><; zcCX`lrw+Mm+CH~PvM2cZ_&l$E3yv?#-98_VU|?Gdm1H@|+juLZX;gp;Pys4H1*pJ9 z0c+H-`F%k~DnJFOz>fm%gI)mxK3mAb$i* L7aA4#3kALbOAH~j literal 0 HcmV?d00001 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml 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..440a7b2 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; @@ -8,6 +14,11 @@ public class Account { private int pinNumber; private double checkingBalance = 0; 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 0000000000000000000000000000000000000000..409ad9b6b1d7f7fe95bf47f91249ae2183aba9ca GIT binary patch literal 6148 zcmeHKJ5EC}5S)b+5i}_&eFbh{Md1Xw03xqJig*Y}|EipeqhLN}2T1f#Za8(M}Vzb?>`J}3?v&VU@ZS-fl=X}%MI1dVkD96Mo$6R7a^eqFHG@ z_Ik&br?|ZZV2jV~Ezkj&(;ad2VQRkbKCz367?I919VS(b35GOiQJnJ z|CQ@|p7(|I_ORK#?DsoQmPr9AAO)m=6p#WZDNyBfes$6*B1-`&aE=Q2_o2}p`@$hH zJ{=sQ1t88C4&yv}31agAu`e7F8KGHHiAl9;F)Znfx611ahs31As`;?G*{VaaxSi*> zNQd=_8l`{~7%Om@%g*cnivCCcKPG7<1*E`PDPXhZ<8r|#Rc)O-&TDO>Khr(uo9@PW oP&h<6CPq2t!pre>BxPRnIrsa*Au;HT2c4*&0oO$)1^!!s9~5&Iv;Y7A literal 0 HcmV?d00001 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