From 65963450ab25ac2eef7ccd7a33d7fd0295255da2 Mon Sep 17 00:00:00 2001 From: "ds.731" <122613372+ds731@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:19:13 -0600 Subject: [PATCH] Expanded application functionality by adding Account class and enhanced data validation using try/catch blocks for exception handling --- bin/bankAcctApp/Account.class | Bin 0 -> 2105 bytes bin/bankAcctApp/BankAcctApp.class | Bin 2246 -> 6028 bytes bin/bankAcctApp/Customer.class | Bin 2328 -> 2620 bytes bin/bankAcctApp/DataEntry.class | Bin 3783 -> 3944 bytes src/bankAcctApp/Account.java | 80 +++++++++++++ src/bankAcctApp/BankAcctApp.java | 186 ++++++++++++++++++++++++++---- src/bankAcctApp/Customer.java | 37 ++++-- src/bankAcctApp/DataEntry.java | 27 +++-- 8 files changed, 289 insertions(+), 41 deletions(-) create mode 100644 bin/bankAcctApp/Account.class create mode 100644 src/bankAcctApp/Account.java diff --git a/bin/bankAcctApp/Account.class b/bin/bankAcctApp/Account.class new file mode 100644 index 0000000000000000000000000000000000000000..eec17a4f7e5a9dfa3740c95f9527101110e9a3c9 GIT binary patch literal 2105 zcmZ{kYfsu>6vzJsg=F7q%VuVl zY#(4BYVMr2Krix1aQ?69fayK_Al8ts<^T8t^ ze5G`hR86T@Qu*SQTG9lJDaQS~_H|Kh3Ya|W>&RNOTCeO17&Vp7Ki{YVysb{@M5TpQ z_qfq6)>P6Jt94Cnsx9rkqLGf+=%~%(rc%~)6JJrG@Fn)LSFKmIeF5&+>V*K$QR7k# z!i@s^@+=_Z)ae`MN~#)5Y2&$zX32Cm3QG_lo^^v_Z>k={sV z%Ct*olIgO<2N^z~#Wu+x_OS26tARc>-X!7xuc^<=jpnsNleXp`j>+ za--cWsV7zLUD0g9Bu^?9DEDpvUbwjBXyxLj(Iu5%msCbwQh{_yLqRe`mNaVg9jDy^ zc@apC#eX0i58Yw%7PDV<^*LRcgN(pK6UDv#h<2i3fXA4poq#8JYC21iWM?Ds?~uOG z!UcBX)ek2u#v?uBXI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@o`A194cBRABW)=hcQ~gWySA8Im&{a*XzNe4r%N>mdlp&cn7B*=I_!oIYs{< bKp)=0yK*uixEuvP1^gCbt55_)5S9N1BlLmO delta 1193 zcmZWoO>Y}j6g|%#dnV&aZI7MQCTZftF>#sd`G>!6eAR9vi%XZ~KX!LuC!!)E41s0+w4PegD@&<-qh=Xp1$Ur_!CkFe3|+JQ zG7AY45_a(dOL+S+AR@*uv50#RasC+_VhR2ui^YdAA|gqG1-)`|vQV%lS65S0x}{H7 zEVH3tH%58TH67Fx+=V!Ur)F3)Qxf*@tFB&Y7~=}=A<9p#sCu7*y*9;5lzcuXVINPr z2X>|vOxUoG;90$9<@B;4A;Z6Q4@MqR@UWdzD0iS_ZYLk%CxpJKDFxGZvcvYXOvA7w zJW7>jOI9P6EbD8r@jbCZQ8#NN>6nZVW)wVT3q%swBni|7Pb8dEaM;Er$4Iy6_$T=9 zo<23N;3+#{S3F-@m2ia5c?Wu)QE+UVKUb_)3>g7DtKd02&u@5R>;(VF7fkPYYl~z(STlj@+1+U;$>S9r^CEz>9s4AqTr~|k zlmFTocCi8<^B>}$`UC6?zvhqevEbgO7d`+A7=1kyJ1KTx2mFMH0J{Y@;lSoi1dd&U zIxA$Z;Nne$Xw#MZ0^MqF3w@e8BwfdyEsSYuD$sEqceik_rrsY2JLm(N`e4BCEca{b zijyHy@j_Skd26U u9PC|^+4K5Wd7f795z-IgFLa6sus?CWP4#$0tlL}CodVr~;R4ZIxcCp5s0Awk diff --git a/bin/bankAcctApp/Customer.class b/bin/bankAcctApp/Customer.class index 9af0451acdc1740070062bb5a673083da51b268e..4d7ef287cc8fb70592d751144709d9ae798dd22f 100644 GIT binary patch delta 668 zcmZwB&r1S96bJAbb#~1|RBYM7Xd}wautkduwS#DaQ6fzg8$wBF8mxkD2O;PW=s1@S z^*1Egp+o%*{SEyGLDz`hyv=^m9^RYxneSWXYV1Mll|2{qID6J{T6VRq7n-$J+pai` zRx=rh{`Un6xuhhoCd4H(L|O@nCuY($%xQ|jQjkkSE>AOPH()ui4cvWJOu7la&bGmd zXs4=4Ic9HFgYALuqrZZe(bxP2I|M&MKld-~%yNrG?nszh3bbi%snAl~@3^vi%hUeUSt22$~?*?v*jjcEKBCjRie(jFE_yk?V7wpPl*=$ftTPed7J&7 ze4qWB{E+;JJ@l36vG@H1HTenqv%hg%))`jcAl8|rsOZe4sOik3P&%8lx=CrdPHDZV a-yt0VfCB;D87R;_10VX(fm0Jrm;L~huToe5 diff --git a/bin/bankAcctApp/DataEntry.class b/bin/bankAcctApp/DataEntry.class index fc639ccda9c7763c895bc17cce67d5d2ff14714d..065a75c689f6ac2fda1f78663fed71983be5b81b 100644 GIT binary patch delta 1908 zcmZ{l+f!3l6vn@kbCR5dBVd3An}kxSN)SX5f`nk@Vr#6R6)h;%HbCSeMlJ!Nj^?3P zdvAAJ1gq6ztF6vx?KI=~(6>%Ib~>GDed#~Y@x}fH*z`LWG2={!nR7O0@4eP`b`=d5SHK=i6;hyoTL+Cih@$q9Za7} z-+dbPqf&yB;1W@+w76c@(1D#QdPSeICp4&GNRP72iqdv;vUen|?>www1V~;p_ zCVVbVI?pMmReT{z)uy})66^>1k4q<1EJz57nCdNxPsjR_BQvE^X=3t7Z+v`WorZ8QkyJ74+L~GhCvs8D&S>lcIIhAvzFnxsdVX2DHq0Z3uX^7_3ynY;Pa9L2KaHt{%&(Q#xm$*p z&(%i6B4&Mzxx6U^n7kA#@Fd?s_-Lp?Y=YlFDmBwuNCZF&{V8!{CEAE-!&ZiLbJZgJ zPSoTu_%ln`vle#f5o}UEt5a^9M_$UL-eFR6rrnsC%lw|j{5Tv;Q%2^en0gfh3b-?()xN z?)a`Uohf7u8wNvzYI<@#au~M|8wpoSP3s61B4Rz;*uYVke~nqN5ewGF?`;OGLe+b4 zz|zzO`95+asW6pG+81%qvceV4E6iKxQ~Ebo+{8qi&S(A# z_!lyF0uSL$7i?ju7KU#{0U>;B=1O)Zh;1yVnWaPtoB}G$j7##?q0b;D1^PMCi8dHj z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new file mode 100644 index 0000000..975bc07 --- /dev/null +++ b/src/bankAcctApp/Account.java @@ -0,0 +1,80 @@ +/* Phase II */ + +package bankAcctApp; + +public class Account { + + private String accountNumber; + private String accountType; + private Double svcFee; + private Double interestRate; + private Double overDraftFee; + private Double balance = 0.00; + + +// Getter and Setter for Account Number info. + public String getAccountNumber() { + return accountNumber; + } + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + +// Getter and Setter for Customer ID info. + public String getAccountType() { + return accountType; + } + public void setAccountType(String accountType) { + this.accountType = accountType; + } + + +// Getter and Setter for Service Fee info. + public Double getSvcFee() { + return svcFee; + } + public void setSvcFee(Double svcFee) { + this.svcFee = svcFee; + } + + +// Getter and Setter for Interest Rate info. + public Double getInterestRate() { + return interestRate; + } + public void setInterestRate(Double interestRate) { + this.interestRate = interestRate; + } + + +// Getter and Setter for Overdraft Fee info. + public Double getOverDraftFee() { + return overDraftFee; + } + public void setOverDraftFee(Double overDraftFee) { + this.overDraftFee = overDraftFee; + } + + +// Getter and Setter for Balance info. + public Double getBalance() { + return balance; + } + public void setBalance(Double balance) { + this.balance = balance; + } + + +// Override the toString() method that is inherited by default in Java. +// Then use the custom-written toString() method to return Account Info +@Override + public String toString() { + return String.format( + "Acct#: Type: Svc Fee: Int Rate: Ovdft Fee: Balance: \n" + + "------ ----- -------- --------- ---------- -------- \n" + + "%-8s %-8s $%-10.2f %-12.1f $%-12.2f $%-9.2f", + accountNumber, accountType, svcFee, interestRate, overDraftFee, balance + ); + } +} \ No newline at end of file diff --git a/src/bankAcctApp/BankAcctApp.java b/src/bankAcctApp/BankAcctApp.java index ff211fa..6e9cbcd 100644 --- a/src/bankAcctApp/BankAcctApp.java +++ b/src/bankAcctApp/BankAcctApp.java @@ -1,40 +1,182 @@ +/* Phase II */ + package bankAcctApp; import java.util.ArrayList; -import java.util.List; +import java.util.InputMismatchException; + public class BankAcctApp { public static void main(String[] args) { + + // Create ArrayLists for the Customer and Account classes. Each ArrayList will store the instances + // created of its respective class, appending each new instance to the end of the list. ArrayList customers = new ArrayList<>(); + ArrayList accounts = new ArrayList<>(); boolean moreCustomers = true; - + +// Create the loop that keeps adding Customer and Account instances until +// the user chooses to quit. while (moreCustomers) { - Customer customer = new Customer(); + + // Create instances of the both the Customer and Account classes. + // These will be stored in their respective class' ArrayList. + Customer customer = new Customer(); + Account account = new Account(); + +// Customer Information: System.out.println("Enter details for new customer:\n"); - - customer.setID(DataEntry.inputStringWithLimit("Customer ID (max 5 chars): ", 5)); - customer.setSSN(DataEntry.inputNumericString("SSN (9 numeric chars): ", 9)); - customer.setLastName(DataEntry.inputStringWithLimit("Last Name (max 20 chars): ", 20)); - customer.setFirstName(DataEntry.inputStringWithLimit("First Name (max 15 chars): ", 15)); - customer.setStreet(DataEntry.inputStringWithLimit("Street (max 20 chars): ", 20)); - customer.setCity(DataEntry.inputStringWithLimit("City (max 20 chars): ", 20)); - customer.setState(DataEntry.inputStringWithLimit("State (2 chars): ", 2)); - customer.setZip(DataEntry.inputNumericString("Zip (5 numeric chars): ", 5)); - customer.setPhone(DataEntry.inputNumericString("Phone (10 numeric chars): ", 10)); - + + // Collect and validate user input for Customer ID info. + try { + customer.setID(DataEntry.inputStringWithLimit("Customer ID (max 5 chars): ", 5)); + } catch (IllegalArgumentException e){ + System.out.println("Customer ID must be 5 alphanumeric characters only. Try again."); + } + + // Collect and validate user input for Social Security Number (SSN). + try { + customer.setSSN(DataEntry.inputNumericString("SSN (9 numeric chars): ", 9)); + } catch (IllegalArgumentException e) { + System.out.println("SSN must be exactly 9 digits. Try again."); + } + + // Collect and validate user input for Last Namee. + try { + customer.setLastName(DataEntry.inputStringWithLimit("Last Name (max 20 chars): ", 20)); + } catch (IllegalArgumentException e) { + System.out.println("Last Name must not contain numbers (0-9) or special characters " + + "(!@#$%^&*(){}[]|). Try again."); + } + + // Collect and validate user input for First Name. + try { + customer.setFirstName(DataEntry.inputStringWithLimit("First Name (max 15 chars): ", 15)); + } catch (IllegalArgumentException e) { + System.out.println("First Name must not contain numbers (0-9) " + + "or special characters (!@#$%^&*(){}[]|). Try again."); + } + + + // Collect and validate user input for Street Address. + try { + customer.setStreet(DataEntry.inputStringWithLimit("Street (max 20 chars): ", 20)); + } catch (IllegalArgumentException e) { + System.out.println("Street must be no more than 20 characters consisting of " + + "numbers, letters, spaces, and \" . , - ' \". Try again."); + } + + // Collect and validate user input for City. + try { + customer.setCity(DataEntry.inputStringWithLimit("City (max 20 chars): ", 20)); + } catch (IllegalArgumentException e) { + System.out.println("City must not contain numbers (0-9) or special characters " + + "(!@#$%^&*(){}[]|). Try again."); + } + + // Collect and validate user input for State. + try { + customer.setState(DataEntry.inputStringWithLimit("State (2 chars): ", 2)); + } catch (InputMismatchException e) { + System.out.println("State must be 2 letters only. Try again."); + } + + // Collect and validate user input for Zip Code. + try { + customer.setZip(DataEntry.inputNumericString("Zip (5 numeric chars): ", 5)); + } catch (NumberFormatException e) { + System.out.println("Zip Code must only contain 5 digits. Try again."); + } + + // Collect and validate user input for Phone Number. + try { + customer.setPhone(DataEntry.inputNumericString("Phone (10 numeric chars): ", 10)); + } catch (NumberFormatException e) { + System.out.println("Phone Number must only contain 9 digits."); + } + +// Store Customer information to the Customer instance. customers.add(customer); - - String more = DataEntry.inputStringWithLimit("\nAdd another customer? (y/n): ", 1); - if (!more.equalsIgnoreCase("y")) { + +// Account Information: + // Collect and validate user input for Account Number. + try { + account.setAccountNumber(DataEntry.inputNumericString("Account Number (5 numeric chars): ", 5)); + } catch (NumberFormatException e) { + System.out.println("Account Number can only be 5 digits. Try again."); + } + + // Collect and validate user input for Account Type. + try { + boolean validAcctType = false; + while (!validAcctType) { + String input = DataEntry.inputStringWithLimit("Account type ('CHK' or 'SVG' only): ", 3); + + if (input.equalsIgnoreCase("CHK") || input.equalsIgnoreCase("SAV")) { + account.setAccountType(input.toUpperCase()); + validAcctType = true; + } else { + System.out.println("Input for Account Type can only be 'CHK' or 'SVG'. Try again."); + } + } + } catch (InputMismatchException e) { + System.out.println("Invalid input. Please try again."); + } + + // Collect and validate user input for Service Fee. + try { + account.setSvcFee(DataEntry.inputDecimalInRange("Service Fee Amount (in dollars and cents): $", 0.00, 10.00)); + } catch (InputMismatchException e) { + System.out.println("Input must be a dollar amount between $0.00 - $10.00. Try again."); + } + + // Collect and validate user input for Interest Rate. + try { + account.setInterestRate(DataEntry.inputDecimalInRange("Interest Rate (percent between 0.0% and 10.0%: ", 0.0, 10.0)); + } catch (InputMismatchException e) { + System.out.println("Interest Rate must be entered as a decimial between 0.0% - 10.0%. Try again."); + } + + // Collect and validate user input for Overdraft Fee. + try { + account.setOverDraftFee(DataEntry.inputDecimal("Overdraft Fee Amount (in dollars and cents): $")); + } catch (InputMismatchException e) { + System.out.println("Input must be a dollar amount between $0.00 and $10.00"); + } + + // Collect and validate user input for Current Balance. + try { + account.setBalance(DataEntry.inputDecimal("Starting Balance (in dollars and cents): $")); + } catch (InputMismatchException e) { + System.out.println("Current Balance must be in dollars and cents. Try again."); + } + +// Add the Account class instance to the accounts ArrayList + accounts.add(account); + +// Prompt user to add additional customers or quit. + String more = DataEntry.inputStringWithLimit("\nAdd another customer? (y/n): ", 1); + if (more.equalsIgnoreCase("n")) { moreCustomers = false; } } - System.out.println("\nCustomer Information:"); - System.out.println("========================================"); - for (Customer c : customers) { - System.out.println(c); +// Print out the results so that each Customer instance and its corresponding Account instance are +// printed together, and so the program iterates through all of the instance pairs in their respective ArrayLists. + System.out.println("\n========================================\n"); + for (int i = 0; i < customers.size(); i++) { + + // Use [int i] for both ArrayLists to ensure the correct Accounts instance is + // printed with the corresponding Customer instance. + Customer customer = customers.get(i); + Account account = accounts.get(i); + + System.out.println(customer + "\n"); + System.out.println(account); + System.out.println("---------------------------------------------------------" + + "----------------------------------------------------------------------------"); + } } -} \ No newline at end of file +} diff --git a/src/bankAcctApp/Customer.java b/src/bankAcctApp/Customer.java index 76f5776..c08dab6 100644 --- a/src/bankAcctApp/Customer.java +++ b/src/bankAcctApp/Customer.java @@ -1,6 +1,10 @@ +/* Phase II */ + package bankAcctApp; + public class Customer { - private String id; + + private String id; private String ssn; private String lastName; private String firstName; @@ -8,8 +12,9 @@ public class Customer { private String city; private String state; private String zip; - private String phone; - + private String phone; + + // Getter and Setter for Customer ID info. public String getID() { return id; @@ -18,6 +23,7 @@ public class Customer { this.id = id; } + // Getter and Setter for Customer SSN info. public String getSSN() { return ssn; @@ -26,6 +32,7 @@ public class Customer { this.ssn = ssn; } + // Getter and Setter for Customer Last Name. public String getLastName() { return lastName; @@ -34,6 +41,7 @@ public class Customer { this.lastName = lastName; } + // Getter and Setter for Customer First Name. public String getFirstName() { return firstName; @@ -42,6 +50,7 @@ public class Customer { this.firstName = firstName; } + // Getter and Setter for Customer Street Address. public String getStreet() { return street; @@ -50,6 +59,7 @@ public class Customer { this.street = street; } + // Getter and Setter for Customer City. public String getCity() { return city; @@ -67,6 +77,7 @@ public class Customer { this.state = state; } + // Getter and Setter for Customer ZIP. public String getZip() { return zip; @@ -75,6 +86,7 @@ public class Customer { this.zip = zip; } + // Getter and Setter for Customer Phone Number. public String getPhone() { return phone; @@ -83,13 +95,18 @@ public class Customer { this.phone = phone; } + // Override the toString() method that is inherited by default from Java's Object class. // Then use the custom-written toString() method to return Customer Info - @Override - public String toString() { - return String.format( - "ID: %s, SSN: %s, Name: %s %s, Address: %s, %s, %s %s, Phone: %s", - id, ssn, firstName, lastName, street, city, state, zip, phone - ); - } +@Override + public String toString() { + return String.format( + "Customer Information:\n" + + "---------------------\n" + + "ID: Last Name: First Name: SSN: Phone: Street: City: ST: ZIP: \n" + + "--- ---------- ----------- ---- ------ ------- ----- --- ---- \n" + + "%-7s %-22s %-17s %-11s %-11s %-22s %-17s %-6s %-7s", + id, lastName, firstName, ssn, phone, street, city, state, zip + ); + } } diff --git a/src/bankAcctApp/DataEntry.java b/src/bankAcctApp/DataEntry.java index 525b8e6..e8329a5 100644 --- a/src/bankAcctApp/DataEntry.java +++ b/src/bankAcctApp/DataEntry.java @@ -1,3 +1,5 @@ +/* Phase II */ + package bankAcctApp; import java.util.Scanner; @@ -18,11 +20,11 @@ public class DataEntry { do { System.out.print(prompt); input = in.nextLine(); - if (input == "" || input.length() > maxLength) { + if (input.isBlank() || input.length() > maxLength) { System.out.println("Invalid input. Must be non-blank and up to " + maxLength + " characters."); } - } while (input == "" || input.length() > maxLength); + } while (input.isBlank() || input.length() > maxLength); return input; } @@ -32,10 +34,10 @@ public class DataEntry { do { System.out.print(prompt); input = in.nextLine(); - if (!input.matches("\\d+")) { - System.out.println("Invalid input. Must only be numeric characters."); + if (!input.matches("\\d{" + length + "}")) { + System.out.println("Invalid input. Must be exactly " + length + " numbers."); } - } while (!input.matches("\\d+")); + } while (!input.matches("\\d{" + length + "}")); return input; } @@ -50,20 +52,23 @@ public class DataEntry { isValid = true; } else { System.out.print("Invalid entry. Try again: "); - in.nextLine(); + in.next(); } + in.nextLine(); } while (!isValid); return input; } -// Static method to validate Integers within a range. +// Static method to validate Integers are within a range. public static int inputIntegerInRange(String prompt, int min, int max) { int input = (min - 1); do { input = inputInteger(prompt); if (input < min || input > max) { System.out.print("Invalid input. Try again: "); + in.next(); } + in.nextLine(); } while (input < min || input > max); return input; } @@ -81,11 +86,12 @@ public class DataEntry { System.out.println("Invalid input. Please enter a valid decimal number."); in.next(); } + in.nextLine(); } while (!isValid); return decimalValue; } -// Static method to validate decimals within a range. +// Static method to validate decimals are within a range. public static double inputDecimalInRange(String prompt, double min, double max) { double value; do { @@ -93,6 +99,7 @@ public class DataEntry { if (value < min || value > max) { System.out.println("Invalid input. Must be between " + min + " and " + max + "."); + in.next(); } } while (value < min || value > max); return value; @@ -109,8 +116,10 @@ public class DataEntry { return input; } else { System.out.print("Invalid date. Please try again: "); + in.next(); } - } while (date == ""); + in.nextLine(); + } while (date.isEmpty()); return date; } }