├── .gitignore ├── LICENSE ├── pom.xml └── src └── main └── java └── io └── diffblue └── corebanking ├── CoreBanking.java ├── CoreBankingException.java ├── Util.java ├── account ├── Account.java └── AccountException.java ├── client └── Client.java ├── compliance ├── CheckCompliance.java └── rules │ ├── ComplianceRule.java │ └── ComplianceRuleBalanceAboveOrEqualToZero.java ├── datamanagement ├── ReadFromDB.java └── WriteToDB.java ├── transaction ├── BankTransaction.java ├── CashTransaction.java ├── Transaction.java └── TransactionException.java └── ui ├── CoreBankingTextUI.java └── menu ├── AccountsMenu.java ├── ClientsMenu.java ├── ComplianceMenu.java ├── CoreBankingDataManagementMenu.java ├── MainMenu.java └── Menu.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2018-2024 Diffblue Limited 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | io.diffblue.corebanking 7 | CoreBanking 8 | 1.0.1-JUnit5 9 | 10 | UTF-8 11 | 1.8 12 | 1.8 13 | 0.8.5 14 | 15 | 16 | 17 | 18 | com.diffblue.cover 19 | cover-annotations 20 | 1.4.0 21 | provided 22 | 23 | 24 | org.mockito 25 | mockito-core 26 | 4.7.0 27 | test 28 | 29 | 30 | org.mockito 31 | mockito-junit-jupiter 32 | 4.7.0 33 | test 34 | 35 | 36 | org.junit.jupiter 37 | junit-jupiter-api 38 | 5.9.0 39 | test 40 | 41 | 42 | org.junit.jupiter 43 | junit-jupiter-engine 44 | 5.9.0 45 | test 46 | 47 | 48 | org.jacoco 49 | org.jacoco.agent 50 | 0.8.2 51 | test 52 | runtime 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.pitest 60 | pitest-maven 61 | 1.5.2 62 | 63 | 64 | org.pitest 65 | pitest-junit5-plugin 66 | 0.12 67 | 68 | 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-assembly-plugin 73 | 2.4.1 74 | 75 | 76 | jar-with-dependencies 77 | 78 | 79 | 80 | 81 | 82 | make-assembly 83 | package 84 | 85 | single 86 | 87 | 88 | 89 | 90 | 91 | org.apache.maven.plugins 92 | maven-compiler-plugin 93 | 3.8.1 94 | 95 | 1.8 96 | 1.8 97 | 98 | 99 | 100 | org.apache.maven.plugins 101 | maven-surefire-plugin 102 | 3.0.0-M3 103 | 104 | 105 | org.junit.platform 106 | junit-platform-surefire-provider 107 | 1.2.0 108 | 109 | 110 | 111 | 112 | org.jacoco 113 | jacoco-maven-plugin 114 | ${jacoco.version} 115 | 116 | 117 | 118 | prepare-agent 119 | 120 | 121 | 122 | report 123 | prepare-package 124 | 125 | report 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/CoreBanking.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | import io.diffblue.corebanking.compliance.CheckCompliance; 21 | import io.diffblue.corebanking.client.Client; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** CoreBanking class. */ 27 | public class CoreBanking { 28 | private final List clients; 29 | private final List accounts; 30 | 31 | /** Constructor. */ 32 | public CoreBanking() { 33 | clients = new ArrayList(); 34 | accounts = new ArrayList(); 35 | } 36 | 37 | /** 38 | * Purges all core banking data, clients and accounts. 39 | */ 40 | public void purgeCoreBanking() { 41 | this.clients.clear(); 42 | this.accounts.clear(); 43 | CheckCompliance.purgeComplianceResults(); 44 | } 45 | 46 | /** 47 | * Generates and returns a valid account number. 48 | * 49 | * @return A valid account number. 50 | */ 51 | private long generateValidAccountNumber() { 52 | long validNumber = 0; 53 | while (validNumber == 0) { 54 | validNumber = Util.generateXdigitNumber(Account.ACCOUNT_NUMBER_LENGTH); 55 | for (int i = 0; i < accounts.size(); i++) { 56 | if (validNumber == accounts.get(i).getAccountNumber()) { 57 | // U-oh, this account number already exists, reset it and try again! 58 | validNumber = 0; 59 | } 60 | } 61 | } 62 | return validNumber; 63 | } 64 | 65 | /** 66 | * Opens a new account. 67 | * 68 | * @param client The client that will own the account. 69 | * @param amount The initial amount in the account. 70 | * @return THe newly created account. 71 | */ 72 | public Account openNewAccount(Client client, long amount) { 73 | long accNumber = generateValidAccountNumber(); 74 | Account account = new Account(accNumber, client, amount); 75 | this.accounts.add(account); 76 | client.addAccount(account); 77 | return account; 78 | } 79 | 80 | /** 81 | * Adds the passed client to the clients in the core banking app. 82 | * 83 | * @param client The client to add to the core banking. 84 | * @return The added client. 85 | */ 86 | public Client registerNewClient(Client client) { 87 | clients.add(client); 88 | return client; 89 | } 90 | 91 | /** 92 | * Returns the list of existing accounts. 93 | * 94 | * @return The list of existing accounts. 95 | */ 96 | public List getAccounts() { 97 | return this.accounts; 98 | } 99 | 100 | /** 101 | * Returns the list of existing clients. 102 | * 103 | * @return The list of existing clients. 104 | */ 105 | public List getClients() { 106 | return this.clients; 107 | } 108 | 109 | /** 110 | * Returns a string representation of the Core Banking application. 111 | * 112 | * @return String representation of the Core Banking application. 113 | */ 114 | public String toString() { 115 | String output = ""; 116 | 117 | for (int i = 0; i < clients.size(); i++) { 118 | output += clients.get(i).toString(); 119 | } 120 | 121 | return output; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/CoreBankingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking; 18 | 19 | /** CoreBankingException. */ 20 | public class CoreBankingException extends Exception { 21 | /** 22 | * Constructor. 23 | * 24 | * @param errorMessage The exception error message. 25 | */ 26 | public CoreBankingException(String errorMessage) { 27 | super(errorMessage); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking; 18 | 19 | /** Utility class. */ 20 | public class Util { 21 | /** 22 | * Generates a number with the number of digits passed as a parameter. 23 | * 24 | * @param numberOfDigits The number of digits for the number to generate. 25 | * @return A randomly generated number with the number of digits passed as the method parameter. 26 | */ 27 | public static long generateXdigitNumber(int numberOfDigits) { 28 | String result = ""; 29 | for (int i = 0; i < numberOfDigits; i++) { 30 | int digit = (int) (Math.random() * 10); 31 | result += digit; 32 | } 33 | return Long.parseLong(result); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/account/Account.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.account; 18 | 19 | import io.diffblue.corebanking.client.Client; 20 | import io.diffblue.corebanking.transaction.Transaction; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** Account class. */ 26 | public class Account { 27 | public static final int ACCOUNT_NUMBER_LENGTH = 4; 28 | private final long accountNumber; 29 | private final Client client; 30 | private final AccountStatement accountStatement = new AccountStatement(); 31 | private long currentBalance; 32 | private String accountName; 33 | private AccountState accountState; 34 | 35 | /** 36 | * The constructor. 37 | * 38 | * @param accountNumber The account number for the account. 39 | * @param client The client owner of the account. 40 | * @param amount The initial amount in the account. 41 | */ 42 | public Account(final long accountNumber, final Client client, final long amount) { 43 | this.accountNumber = accountNumber; 44 | this.client = client; 45 | currentBalance = amount; 46 | accountName = "Current"; 47 | accountState = AccountState.OPEN; 48 | } 49 | 50 | /** 51 | * The account number. 52 | * 53 | * @return The account number. 54 | */ 55 | public long getAccountNumber() { 56 | return accountNumber; 57 | } 58 | 59 | /** 60 | * The client owner of the account. 61 | * 62 | * @return The client owner of the account. 63 | */ 64 | public Client getClient() { 65 | return client; 66 | } 67 | 68 | /** 69 | * Returns the account statement. 70 | * 71 | * @return The account statement. 72 | */ 73 | public AccountStatement getAccountStatement() { 74 | return accountStatement; 75 | } 76 | 77 | /** 78 | * Returns the current balance. 79 | * 80 | * @return The current balance. 81 | */ 82 | public long getCurrentBalance() { 83 | return currentBalance; 84 | } 85 | 86 | /** 87 | * Adds the passed amount to the balance of the account. 88 | * 89 | * @param amount The amount to add to the balance. 90 | * @throws AccountException If the account is not in an OPEN state. 91 | */ 92 | public void addToBalance(final long amount) throws AccountException { 93 | if (getAccountState() != AccountState.OPEN) { 94 | throw new AccountException("Cannot add to balance, account is closed."); 95 | } 96 | currentBalance += amount; 97 | } 98 | 99 | /** 100 | * Takes the passed amount from the existing balance. 101 | * 102 | * @param amount The amount to take. 103 | * @throws AccountException If the account is not OPEN, of the balance is lower than the amount to 104 | * take. 105 | */ 106 | public void takeFromBalance(final long amount) throws AccountException { 107 | if (getAccountState() != AccountState.OPEN) { 108 | throw new AccountException("Cannot take from balance, account is closed."); 109 | } 110 | if (currentBalance - amount < 0) { 111 | throw new AccountException( 112 | "Trying to take " 113 | + amount 114 | + " from the existing balance of " 115 | + currentBalance 116 | + ". Not enough funds."); 117 | } 118 | currentBalance -= amount; 119 | } 120 | 121 | /** 122 | * Returns the account name. 123 | * 124 | * @return The account name. 125 | */ 126 | public String getAccountName() { 127 | return accountName; 128 | } 129 | 130 | /** 131 | * Sets the account name to the passed string. 132 | * 133 | * @param accountName The account name to set. 134 | * @throws AccountException If the account is not in an OPEN state. 135 | */ 136 | public void setAccountName(final String accountName) throws AccountException { 137 | if (getAccountState() != AccountState.OPEN) { 138 | throw new AccountException("Cannot change account name, account is closed."); 139 | } 140 | this.accountName = accountName; 141 | } 142 | 143 | /** 144 | * Returns the current account state. 145 | * 146 | * @return The current account state. 147 | */ 148 | public AccountState getAccountState() { 149 | return accountState; 150 | } 151 | 152 | /** 153 | * Closes the account. 154 | * 155 | * @throws AccountException If the account is not in an OPEN state. 156 | */ 157 | public void closeAccount() throws AccountException { 158 | if (getAccountState() != AccountState.OPEN) { 159 | throw new AccountException("Account is already closed."); 160 | } 161 | accountState = AccountState.CLOSED; 162 | } 163 | 164 | /** 165 | * Adds a transaction to the account transaction statement. 166 | * 167 | * @param transaction The transaction to add. 168 | * @throws AccountException If the account is not in an OPEN state. 169 | */ 170 | public void addTransaction(final Transaction transaction) throws AccountException { 171 | if (getAccountState() != AccountState.OPEN) { 172 | throw new AccountException("The account is closed, you cannot add a transaction."); 173 | } 174 | accountStatement.addTransaction(transaction); 175 | } 176 | 177 | /** 178 | * Returns a string representation of the account. 179 | * 180 | * @return String representation of the account. 181 | */ 182 | public String toString() { 183 | String output = "Account: | "; 184 | 185 | output += 186 | "Acc #: " 187 | + getAccountNumber() 188 | + "\t | " 189 | + "Acc name: " 190 | + getAccountName() 191 | + "\t | " 192 | + "Acc holder: " 193 | + getClient().getClientName() 194 | + "\t | " 195 | + "Acc balance: " 196 | + getCurrentBalance() 197 | + "\t | " 198 | + "Acc state: " 199 | + getAccountState() 200 | + "\t |\n"; 201 | 202 | output += accountStatement.toString(); 203 | 204 | return output; 205 | } 206 | 207 | /** AccountState. */ 208 | public enum AccountState { 209 | OPEN, 210 | CLOSED 211 | } 212 | 213 | @Override 214 | public boolean equals(Object o) { 215 | if (this == o) return true; 216 | if (o == null) return false; 217 | if (!(o instanceof Account)) return false; 218 | Account account = (Account) o; 219 | return accountNumber == account.accountNumber; 220 | } 221 | 222 | /** AccountStatement of an account, which holds the list of all executed transactions. */ 223 | public class AccountStatement { 224 | private final List transactions; 225 | 226 | /** Constructor. */ 227 | public AccountStatement() { 228 | transactions = new ArrayList(); 229 | } 230 | 231 | /** 232 | * returns the transactions list. 233 | * 234 | * @return The transactions list. 235 | */ 236 | public List getTransactions() { 237 | return transactions; 238 | } 239 | 240 | /** 241 | * Adds the passed transaction instance to the transactions list. 242 | * 243 | * @param transaction The transaction to add to the transactions list. 244 | */ 245 | private void addTransaction(final Transaction transaction) { 246 | transactions.add(transaction); 247 | } 248 | 249 | /** 250 | * Returns a string representation of the Account Statement. 251 | * 252 | * @return String representation of the Account Statement. 253 | */ 254 | public String toString() { 255 | String output = ""; 256 | 257 | if (transactions.size() == 0) { 258 | return "Account statement empty."; 259 | } 260 | for (int i = transactions.size() - 1; i >= 0; i--) { 261 | output += transactions.get(i) + "\n"; 262 | } 263 | 264 | return output; 265 | } 266 | 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/account/AccountException.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.account; 18 | 19 | import io.diffblue.corebanking.CoreBankingException; 20 | 21 | /** AccountStatement exception. */ 22 | public class AccountException extends CoreBankingException { 23 | /** 24 | * The constructor. 25 | * 26 | * @param errorMesssage The exception error message. 27 | */ 28 | public AccountException(String errorMesssage) { 29 | super(errorMesssage); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/client/Client.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.client; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** A bank client. */ 25 | public class Client { 26 | private String clientName; 27 | private List accounts; 28 | 29 | /** 30 | * Constructor. 31 | * 32 | * @param clientName The name of the client. 33 | */ 34 | public Client(String clientName) { 35 | this.clientName = clientName; 36 | this.accounts = new ArrayList<>(); 37 | } 38 | 39 | /** 40 | * Returns the client name. 41 | * 42 | * @return The client name. 43 | */ 44 | public String getClientName() { 45 | return this.clientName; 46 | } 47 | 48 | /** 49 | * Adds an account to this client. 50 | * 51 | * @param account The account to add to the client. 52 | */ 53 | public void addAccount(Account account) { 54 | this.accounts.add(account); 55 | } 56 | 57 | /** 58 | * Returns the list of all accounts of the client. 59 | * 60 | * @return The list of all accounts of the client. 61 | */ 62 | public List getAccounts() { 63 | return this.accounts; 64 | } 65 | 66 | /** 67 | * Returns a string representation of the client. 68 | * 69 | * @return String representation of the client. 70 | */ 71 | public String toString() { 72 | String output = ""; 73 | 74 | output += "Client name: " + this.clientName + "\n"; 75 | for (int j = 0; j < this.getAccounts().size(); j++) { 76 | output += this.getAccounts().get(j).toString() + "\n"; 77 | } 78 | 79 | if(output.isEmpty()) { 80 | // Dead code 81 | output += "The details of this client are empty."; 82 | } 83 | 84 | return output; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/compliance/CheckCompliance.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.compliance; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | import io.diffblue.corebanking.compliance.rules.ComplianceRule; 21 | import io.diffblue.corebanking.compliance.rules.ComplianceRuleBalanceAboveOrEqualToZero; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | public class CheckCompliance { 27 | 28 | public static final List COMPLIANCE_RULES = new ArrayList(); 29 | 30 | static { 31 | COMPLIANCE_RULES.add(new ComplianceRuleBalanceAboveOrEqualToZero()); 32 | } 33 | 34 | /** 35 | * Checks that the passed accounts are compliant with all the compliance rules. 36 | * 37 | * @param accountsToVerify Accounts to check compliance against the compliance rules. 38 | * @return The accounts that failed the compliance rules. 39 | */ 40 | public static void checkAccountCompliance(List accountsToVerify) { 41 | 42 | // For all the passed accounts 43 | for (Account a : accountsToVerify) { 44 | 45 | // Loop through all the existing compliance rules 46 | for (ComplianceRule rule : COMPLIANCE_RULES) { 47 | rule.validateAccountCompliance(a); 48 | } 49 | } 50 | } 51 | 52 | /** 53 | * Outputs the result of the compliance check, printing the compliant accounts followed by failed 54 | * accounts. 55 | */ 56 | public static void viewComplianceCheckResults() {} 57 | 58 | /** Purges the previously stored compliance check results (passed/failed accounts). */ 59 | public static void purgeComplianceResults() { 60 | for (ComplianceRule rule : COMPLIANCE_RULES) { 61 | rule.purgeAccounts(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/compliance/rules/ComplianceRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.compliance.rules; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | public abstract class ComplianceRule { 25 | 26 | private final List currentNonCompliantAccounts = new ArrayList(); 27 | private final List currentCompliantAccounts = new ArrayList(); 28 | 29 | /** 30 | * Adds the passed account to the list of non-compliant accounts. 31 | * @param account The non-compliant account. 32 | */ 33 | public void addToNonCompliantAccounts(Account account) { 34 | if (currentNonCompliantAccounts.contains(account)) { 35 | throw new IllegalStateException(); 36 | } 37 | currentNonCompliantAccounts.add(account); 38 | } 39 | 40 | /** 41 | * Adds the passed account to the list of compliant accounts. 42 | * @param account The compliant account. 43 | */ 44 | public void addToCompliantAccounts(Account account) { 45 | if (currentCompliantAccounts.contains(account)) { 46 | throw new IllegalStateException(); 47 | } 48 | currentCompliantAccounts.add(account); 49 | } 50 | 51 | /** 52 | * Makes sure the passed account is not in any compliance list. 53 | * @param account The account to remove from all compliance lists. 54 | */ 55 | public void removeFromComplianceLists(Account account) { 56 | this.currentNonCompliantAccounts.remove(account); 57 | this.currentCompliantAccounts.remove(account); 58 | } 59 | 60 | /** 61 | * Returns the list of non-compliant accounts. 62 | * @return The list of non-compliant accounts. 63 | */ 64 | public List getNonCompliantAccounts() { 65 | return this.currentNonCompliantAccounts; 66 | } 67 | 68 | /** 69 | * Returns the list of compliant accounts. 70 | * @return The list of compliant accounts. 71 | */ 72 | public List getCompliantAccounts() { 73 | return this.currentCompliantAccounts; 74 | } 75 | 76 | /** 77 | * Checks if the passed account passes or fails this rule. 78 | * 79 | * @param account The account to verify compliance. 80 | */ 81 | public abstract void validateAccountCompliance(Account account); 82 | 83 | /** Purges all accounts from the rules. */ 84 | public void purgeAccounts() { 85 | this.currentNonCompliantAccounts.clear(); 86 | this.currentCompliantAccounts.clear(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleBalanceAboveOrEqualToZero.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.compliance.rules; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | 21 | public class ComplianceRuleBalanceAboveOrEqualToZero extends ComplianceRule { 22 | 23 | /** 24 | * Checks if the passed account passes or fails this rule. 25 | * 26 | * @param account The account to verify compliance. 27 | */ 28 | public void validateAccountCompliance(Account account) { 29 | 30 | // Make sure the account does not belong to any list. 31 | this.removeFromComplianceLists(account); 32 | 33 | // Check if this account passes or fails this rule. 34 | if (account.getCurrentBalance() >= 0) { 35 | addToCompliantAccounts(account); 36 | } else { 37 | addToNonCompliantAccounts(account); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/datamanagement/ReadFromDB.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.datamanagement; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | import io.diffblue.corebanking.transaction.CashTransaction; 21 | import io.diffblue.corebanking.transaction.TransactionException; 22 | import io.diffblue.corebanking.CoreBanking; 23 | import io.diffblue.corebanking.client.Client; 24 | 25 | import java.util.Date; 26 | 27 | public class ReadFromDB { 28 | public static CoreBanking readFromDB() throws TransactionException { 29 | CoreBanking coreBanking = new CoreBanking(); 30 | readFromDB(coreBanking); 31 | return coreBanking; 32 | } 33 | 34 | public static void readFromDB(CoreBanking coreBanking) throws TransactionException { 35 | coreBanking.purgeCoreBanking(); 36 | 37 | tempStaticData(coreBanking); 38 | } 39 | 40 | private static void tempStaticData(CoreBanking coreBanking) throws TransactionException { 41 | // Clients 1 42 | Client client1 = new Client("John Field"); 43 | Account acc1cli1 = coreBanking.openNewAccount(client1, 100); 44 | Account acc2cli1 = coreBanking.openNewAccount(client1, 100); 45 | Account acc3cli1 = coreBanking.openNewAccount(client1, 100); 46 | 47 | // Client 2 48 | Client client2 = new Client("Jane Robbins"); 49 | 50 | Account acc1cli2 = coreBanking.openNewAccount(client2, 100); 51 | Account acc2cli2 = coreBanking.openNewAccount(client2, 100); 52 | 53 | // Client 3 54 | Client client3 = new Client("Emily Simmons"); 55 | 56 | Account acc1cli3 = coreBanking.openNewAccount(client3, 100); 57 | 58 | // Add clients to coreBanking. 59 | coreBanking.registerNewClient(client1); 60 | coreBanking.registerNewClient(client2); 61 | coreBanking.registerNewClient(client3); 62 | 63 | // Cash Transactions -- Add 100 to each account 64 | new CashTransaction(100, new Date(2019, 11, 10), acc1cli1).executeTransaction(); 65 | new CashTransaction(100, new Date(2019, 11, 11), acc2cli1).executeTransaction(); 66 | new CashTransaction(100, new Date(2019, 11, 12), acc3cli1).executeTransaction(); 67 | new CashTransaction(100, new Date(2019, 11, 13), acc1cli2).executeTransaction(); 68 | new CashTransaction(100, new Date(2019, 11, 14), acc2cli2).executeTransaction(); 69 | new CashTransaction(100, new Date(2019, 11, 15), acc1cli3).executeTransaction(); 70 | 71 | // Cash transactions, invalid 72 | new CashTransaction(-500, new Date(2019, 11, 13), acc1cli1).executeTransaction(); 73 | 74 | // Bank Transactions 75 | // new BankTransaction(100, new Date(2019, 11, 15), acc1cli1, 76 | // acc2cli1).executeTransaction(); 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/datamanagement/WriteToDB.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.datamanagement; 18 | 19 | import io.diffblue.corebanking.CoreBanking; 20 | 21 | public class WriteToDB { 22 | public static void writeToDisk(CoreBanking coreBanking) { 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/transaction/BankTransaction.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.transaction; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | import io.diffblue.corebanking.account.AccountException; 21 | 22 | import java.util.Date; 23 | 24 | public class BankTransaction extends Transaction { 25 | private final Account sourceAcc; 26 | private final Account targetAcc; 27 | 28 | /** 29 | * BankTransaction constructor. 30 | * 31 | * @param amount The amount of the transaction. 32 | * @param date The date of the transaction. 33 | * @param sourceAcc The source account. 34 | * @param targetAcc The target account. 35 | */ 36 | public BankTransaction(long amount, Date date, Account sourceAcc, Account targetAcc) { 37 | super(amount, date); 38 | this.sourceAcc = sourceAcc; 39 | this.targetAcc = targetAcc; 40 | } 41 | 42 | /** 43 | * Returns the source account number. 44 | * 45 | * @return The source account number. 46 | */ 47 | public String getSource() { 48 | return "" + this.sourceAcc.getAccountNumber(); 49 | } 50 | 51 | /** 52 | * Returns the target account number. 53 | * 54 | * @return The target account number. 55 | */ 56 | public String getTarget() { 57 | return "" + this.targetAcc.getAccountNumber(); 58 | } 59 | 60 | /** 61 | * Clones a BankTransaction instance. 62 | * 63 | * @return The cloned instance. 64 | */ 65 | private BankTransaction cloneBankTransaction() { 66 | BankTransaction clone = 67 | new BankTransaction( 68 | this.getTransactionAmount(), this.getTransactionDate(), this.sourceAcc, this.targetAcc); 69 | clone.transactionState = this.transactionState; 70 | return clone; 71 | } 72 | 73 | /** 74 | * Executes the BankTransaction. 75 | * 76 | * @throws TransactionException If the transaction was previously executed, or if at least one of 77 | * the accounts is closed. 78 | */ 79 | public void executeTransaction() throws TransactionException { 80 | if (targetAcc.getAccountState() != Account.AccountState.OPEN 81 | || sourceAcc.getAccountState() != Account.AccountState.OPEN) { 82 | throw new TransactionException("Both accounts must be in an open state."); 83 | } 84 | if (this.getTransactionState() != TransactionState.NOT_EXECUTED_YET) { 85 | throw new TransactionException("This transaction was already executed!"); 86 | } 87 | 88 | // Execute the transaction 89 | try { 90 | this.sourceAcc.takeFromBalance(this.getTransactionAmount()); 91 | this.targetAcc.addToBalance(this.getTransactionAmount()); 92 | this.setAccountBalanceAfterTransaction(this.targetAcc.getCurrentBalance()); 93 | this.markTransactionAsExecuted(); 94 | } catch (AccountException e) { 95 | e.printStackTrace(); 96 | this.setAccountBalanceAfterTransaction(this.targetAcc.getCurrentBalance()); 97 | this.setCurrentStateFailed(); 98 | throw new TransactionException(e.getMessage()); 99 | } 100 | 101 | // Add transaction to statements 102 | try { 103 | BankTransaction cloneForSource = this.cloneBankTransaction(); 104 | cloneForSource.setAccountBalanceAfterTransaction(sourceAcc.getCurrentBalance()); 105 | this.sourceAcc.addTransaction(cloneForSource); 106 | this.targetAcc.addTransaction(this); 107 | } catch (AccountException e) { 108 | e.printStackTrace(); 109 | throw new TransactionException(e.getMessage()); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/transaction/CashTransaction.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.transaction; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | import io.diffblue.corebanking.account.AccountException; 21 | 22 | import java.util.Date; 23 | 24 | public class CashTransaction extends Transaction { 25 | private Account account; 26 | private CashTransactionType cashTransactionType; 27 | 28 | /** 29 | * CashTransaction constructor 30 | * 31 | * @param amount The amount of the cash transaction. 32 | * @param date The date of the transaction. 33 | * @param targetAccount The target account where the cash will be deposited. 34 | */ 35 | public CashTransaction(long amount, Date date, Account targetAccount) { 36 | super(amount, date); 37 | this.account = targetAccount; 38 | if (amount >= 0) { 39 | cashTransactionType = CashTransactionType.DEPOSIT; 40 | } else { 41 | cashTransactionType = CashTransactionType.WITHDRAWAL; 42 | } 43 | } 44 | 45 | /** 46 | * Returns "CASH" or the account number, depending on whether the transaction is a deposit or a 47 | * withdrawal. 48 | * 49 | * @return "CASH", or the account number. 50 | */ 51 | public String getSource() { 52 | if (cashTransactionType == CashTransactionType.DEPOSIT) { 53 | return "CASH"; 54 | } else { 55 | return "" + this.account.getAccountNumber(); 56 | } 57 | } 58 | 59 | /** 60 | * Returns "CASH" or the account number, depending on whether the transaction is a deposit or a 61 | * withdrawal. 62 | * 63 | * @return "CASH", or the account number. 64 | */ 65 | public String getTarget() { 66 | if (cashTransactionType == CashTransactionType.WITHDRAWAL) { 67 | return "CASH"; 68 | } else { 69 | return "" + this.account.getAccountNumber(); 70 | } 71 | } 72 | 73 | /** 74 | * Executes the transaction. 75 | * 76 | * @throws TransactionException If the transaction was previously executed, or if at least one of 77 | * the accounts is closed. 78 | */ 79 | public void executeTransaction() throws TransactionException { 80 | if (account.getAccountState() != Account.AccountState.OPEN) { 81 | throw new TransactionException("The target account is closed."); 82 | } 83 | 84 | if (this.getTransactionState() != TransactionState.NOT_EXECUTED_YET) { 85 | throw new TransactionException("This transaction was already executed!"); 86 | } 87 | 88 | // Execute the transaction 89 | try { 90 | 91 | if (cashTransactionType == CashTransactionType.DEPOSIT) { 92 | account.addToBalance(this.getTransactionAmount()); 93 | } else if (cashTransactionType == CashTransactionType.WITHDRAWAL) { 94 | account.takeFromBalance(this.getTransactionAmount()); 95 | } 96 | this.setAccountBalanceAfterTransaction(this.account.getCurrentBalance()); 97 | this.markTransactionAsExecuted(); 98 | } catch (AccountException e) { 99 | System.out.println(e.getMessage()); 100 | this.setAccountBalanceAfterTransaction(this.account.getCurrentBalance()); 101 | this.setCurrentStateFailed(); 102 | } 103 | 104 | // Add to statement 105 | try { 106 | this.account.addTransaction(this); 107 | } catch (AccountException e) { 108 | e.printStackTrace(); 109 | throw new TransactionException(e.getMessage()); 110 | } 111 | } 112 | 113 | private enum CashTransactionType { 114 | DEPOSIT, 115 | WITHDRAWAL 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/transaction/Transaction.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.transaction; 18 | 19 | import java.text.SimpleDateFormat; 20 | import java.util.Date; 21 | 22 | /** Transaction class. */ 23 | public abstract class Transaction { 24 | private final long transactionAmount; 25 | private final Date transactionDate; 26 | protected TransactionState transactionState; 27 | private long accountBalanceAfterTransaction; 28 | 29 | /** 30 | * Transaction constructor. 31 | * 32 | * @param amount The amount for the transaction. 33 | * @param transactionDate The transaction date. 34 | */ 35 | public Transaction(long amount, Date transactionDate) { 36 | this.transactionAmount = amount; 37 | this.transactionState = TransactionState.NOT_EXECUTED_YET; 38 | this.transactionDate = transactionDate; 39 | } 40 | 41 | /** 42 | * The source of the transaction. 43 | * 44 | * @return The source. 45 | */ 46 | public abstract String getSource(); 47 | 48 | /** 49 | * The target of the transastion. 50 | * 51 | * @return The target. 52 | */ 53 | public abstract String getTarget(); 54 | 55 | /** 56 | * The amount of the transaction. 57 | * 58 | * @return The amount of the transaction. 59 | */ 60 | public long getTransactionAmount() { 61 | return this.transactionAmount; 62 | } 63 | 64 | /** 65 | * The transaction date. 66 | * 67 | * @return The transaction date. 68 | */ 69 | public Date getTransactionDate() { 70 | return this.transactionDate; 71 | } 72 | 73 | /** 74 | * The current state of this transaction. 75 | * 76 | * @return The current state of this transaction. 77 | */ 78 | public TransactionState getTransactionState() { 79 | return this.transactionState; 80 | } 81 | 82 | /** 83 | * Sets the passed balance as the balance in the target account after the transaction. 84 | * 85 | * @param accountBalanceAfterTransaction The balance to set. 86 | * @throws TransactionException If the transaction was already executed. 87 | */ 88 | protected void setAccountBalanceAfterTransaction(long accountBalanceAfterTransaction) 89 | throws TransactionException { 90 | this.accountBalanceAfterTransaction = accountBalanceAfterTransaction; 91 | } 92 | 93 | /** 94 | * Sets the transaction to a failed state. 95 | * 96 | * @throws TransactionException If the transaction was not in a not-executed state. 97 | */ 98 | public void setCurrentStateFailed() throws TransactionException { 99 | if (this.transactionState != TransactionState.NOT_EXECUTED_YET) { 100 | throw new TransactionException( 101 | "This transaction was already executed, cannot be set to Failed."); 102 | } 103 | this.transactionState = TransactionState.FAILED; 104 | } 105 | 106 | /** 107 | * Executes the transaction. 108 | * 109 | * @throws TransactionException If executing the transaction fails. 110 | */ 111 | public abstract void executeTransaction() throws TransactionException; 112 | 113 | protected void markTransactionAsExecuted() { 114 | this.transactionState = TransactionState.EXECUTED; 115 | } 116 | 117 | /** 118 | * Returns a string representation of the transaction. 119 | * 120 | * @return String representation of the transaction. 121 | */ 122 | public String toString() { 123 | String output = "Transaction: | "; 124 | 125 | output += 126 | new SimpleDateFormat("yy.MM.dd").format(transactionDate) 127 | + "\t| " 128 | + "Source: " 129 | + this.getSource() 130 | + "\t| " 131 | + "Target: " 132 | + this.getTarget() 133 | + "\t| " 134 | + "Amount: " 135 | + this.transactionAmount 136 | + "\t| " 137 | + "Balance: " 138 | + this.accountBalanceAfterTransaction 139 | + "\t| " 140 | + "Transaction state: " 141 | + this.getTransactionState() 142 | + "\t|"; 143 | 144 | return output; 145 | } 146 | 147 | /** TransactionState Enum. */ 148 | public enum TransactionState { 149 | NOT_EXECUTED_YET, 150 | EXECUTED, 151 | FAILED 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/transaction/TransactionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.transaction; 18 | 19 | /** TransactionException class. */ 20 | public class TransactionException extends Exception { 21 | 22 | /** 23 | * TransactionException constructor. 24 | * 25 | * @param errorMsg The error message of the Exception. 26 | */ 27 | public TransactionException(String errorMsg) { 28 | super(errorMsg); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/ui/CoreBankingTextUI.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.ui; 18 | 19 | import io.diffblue.corebanking.CoreBanking; 20 | import io.diffblue.corebanking.datamanagement.ReadFromDB; 21 | import io.diffblue.corebanking.transaction.TransactionException; 22 | import io.diffblue.corebanking.ui.menu.MainMenu; 23 | import io.diffblue.corebanking.ui.menu.Menu; 24 | 25 | public class CoreBankingTextUI { 26 | private final CoreBanking coreBanking; 27 | 28 | /** 29 | * The constructor. 30 | * 31 | * @param coreBanking The CoreBanking instance to work with. 32 | */ 33 | public CoreBankingTextUI(CoreBanking coreBanking) { 34 | this.coreBanking = coreBanking; 35 | } 36 | 37 | /** 38 | * The main method. 39 | * 40 | * @param args Command line arguments. 41 | */ 42 | public static void main(String[] args) { 43 | try { 44 | // Create core banking instance 45 | CoreBankingTextUI textUI = new CoreBankingTextUI(ReadFromDB.readFromDB()); 46 | textUI.startTextUI(); 47 | 48 | } catch (TransactionException e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | 53 | /** Starts the TextUI. */ 54 | private void startTextUI() { 55 | Menu mainMenu = new MainMenu(coreBanking); 56 | mainMenu.startMenu(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/ui/menu/AccountsMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.ui.menu; 18 | 19 | import io.diffblue.corebanking.account.Account; 20 | import io.diffblue.corebanking.CoreBanking; 21 | 22 | public class AccountsMenu extends Menu { 23 | private static final String MENU_TITLE = "Accounts Menu"; 24 | private static final String[] MENU_MAIN = 25 | new String[] { 26 | "1. Display all accounts", "2. Open new account", "3. Close account", "0. Back" 27 | }; 28 | 29 | /** 30 | * Constructor. 31 | * 32 | * @param coreBanking CoreBanking instance. 33 | */ 34 | public AccountsMenu(CoreBanking coreBanking) { 35 | super(MENU_TITLE, MENU_MAIN, coreBanking); 36 | } 37 | 38 | /** 39 | * Executes the passed menu option. 40 | * 41 | * @param menuOpt The menu option to execute. 42 | */ 43 | protected void executeMenuOption(int menuOpt) { 44 | switch (menuOpt) { 45 | case 1: 46 | viewAccounts(); 47 | break; 48 | case 2: 49 | createNewAccount(); 50 | break; 51 | case 0: 52 | System.out.println(); 53 | break; 54 | default: 55 | System.out.println("This should never happen... Invalid option: " + menuOpt); 56 | break; 57 | } 58 | } 59 | 60 | /** Outputs the existing accounts to stdout. */ 61 | private void viewAccounts() { 62 | for (Account account : this.coreBanking.getAccounts()) { 63 | System.out.println(account); 64 | } 65 | } 66 | 67 | /** 68 | * Takes the input required to create a new account, and creates it, adding it to the CoreBanking 69 | * instance. 70 | */ 71 | private void createNewAccount() {} 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/ui/menu/ClientsMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.ui.menu; 18 | 19 | import io.diffblue.corebanking.CoreBanking; 20 | import io.diffblue.corebanking.client.Client; 21 | 22 | import java.io.BufferedReader; 23 | import java.io.IOException; 24 | import java.io.InputStreamReader; 25 | 26 | public class ClientsMenu extends Menu { 27 | private static final String MENU_TITLE = "Clients Menu"; 28 | private static final String[] MENU_MAIN = 29 | new String[] {"1. Display clients", "2. Register new client", "0. Back"}; 30 | 31 | /** 32 | * Constructor. 33 | * 34 | * @param coreBanking CoreBanking instance. 35 | */ 36 | public ClientsMenu(CoreBanking coreBanking) { 37 | super(MENU_TITLE, MENU_MAIN, coreBanking); 38 | } 39 | 40 | /** 41 | * Executes the passed menu option. 42 | * 43 | * @param menuOpt The menu option to execute. 44 | */ 45 | protected void executeMenuOption(int menuOpt) { 46 | switch (menuOpt) { 47 | case 1: 48 | viewClients(); 49 | break; 50 | case 2: 51 | registerNewClient(); 52 | break; 53 | case 0: 54 | System.out.println(); 55 | break; 56 | default: 57 | System.out.println("This should never happen... Invalid option: " + menuOpt); 58 | break; 59 | } 60 | } 61 | 62 | /** Outputs the existing clients to stdout. */ 63 | private void viewClients() { 64 | for (Client client : this.coreBanking.getClients()) { 65 | System.out.println(client); 66 | } 67 | } 68 | 69 | /** Registers a new client. */ 70 | private void registerNewClient() { 71 | System.out.println("Enter new client name: "); 72 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 73 | try { 74 | String clientName = reader.readLine(); 75 | coreBanking.registerNewClient(new Client(clientName)); 76 | System.out.println("Client registered."); 77 | } catch (IOException e) { 78 | System.out.println("Client name invalid."); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/ui/menu/ComplianceMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.ui.menu; 18 | 19 | import io.diffblue.corebanking.compliance.CheckCompliance; 20 | import io.diffblue.corebanking.CoreBanking; 21 | 22 | public class ComplianceMenu extends Menu { 23 | private static final String MENU_TITLE = "Compliance Menu"; 24 | private static final String[] MENU_MAIN = 25 | new String[] {"1. Run compliance check", "2. View last compliance results", "0. Back"}; 26 | 27 | /** 28 | * Constructor. 29 | * 30 | * @param coreBanking CoreBanking instance. 31 | */ 32 | public ComplianceMenu(CoreBanking coreBanking) { 33 | super(MENU_TITLE, MENU_MAIN, coreBanking); 34 | } 35 | 36 | /** 37 | * Executes the passed menu option. 38 | * 39 | * @param menuOpt The menu option to execute. 40 | */ 41 | protected void executeMenuOption(int menuOpt) { 42 | switch (menuOpt) { 43 | case 1: 44 | CheckCompliance.checkAccountCompliance(this.coreBanking.getAccounts()); 45 | break; 46 | case 2: 47 | CheckCompliance.viewComplianceCheckResults(); 48 | break; 49 | case 0: 50 | System.out.println(); 51 | break; 52 | default: 53 | System.out.println("This should never happen... Invalid option: " + menuOpt); 54 | break; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/ui/menu/CoreBankingDataManagementMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.ui.menu; 18 | 19 | import io.diffblue.corebanking.datamanagement.ReadFromDB; 20 | import io.diffblue.corebanking.datamanagement.WriteToDB; 21 | import io.diffblue.corebanking.transaction.TransactionException; 22 | import io.diffblue.corebanking.CoreBanking; 23 | 24 | public class CoreBankingDataManagementMenu extends Menu { 25 | private static final String MENU_TITLE = "CoreBanking Data Management Menu"; 26 | private static final String[] MENU_MAIN = 27 | new String[] { 28 | "1. Write CoreBanking data to DB", "2. Load CoreBanking data from DB", "0. Back" 29 | }; 30 | 31 | /** 32 | * Constructor. 33 | * 34 | * @param coreBanking CoreBanking instance. 35 | */ 36 | public CoreBankingDataManagementMenu(CoreBanking coreBanking) { 37 | super(MENU_TITLE, MENU_MAIN, coreBanking); 38 | } 39 | 40 | /** 41 | * Executes the passed menu option. 42 | * 43 | * @param menuOpt The menu option to execute. 44 | */ 45 | protected void executeMenuOption(int menuOpt) { 46 | switch (menuOpt) { 47 | case 1: 48 | WriteToDB.writeToDisk(coreBanking); 49 | break; 50 | case 2: 51 | try { 52 | ReadFromDB.readFromDB(coreBanking); 53 | } catch (TransactionException e) { 54 | e.printStackTrace(); 55 | } 56 | break; 57 | case 0: 58 | System.out.println(); 59 | break; 60 | default: 61 | System.out.println("This should never happen... Invalid option: " + menuOpt); 62 | break; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/ui/menu/MainMenu.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.ui.menu; 18 | 19 | import io.diffblue.corebanking.CoreBanking; 20 | 21 | public class MainMenu extends Menu { 22 | private static final String MENU_TITLE = "Main Menu"; 23 | private static final String[] MENU_MAIN = 24 | new String[] { 25 | "1. Clients menu", 26 | "2. Accounts menu", 27 | "3. Compliance menu", 28 | "4. Core Banking data management menu", 29 | "0. Exit Core Banking" 30 | }; 31 | 32 | /** 33 | * Constructor. 34 | * 35 | * @param coreBanking CoreBanking instance. 36 | */ 37 | public MainMenu(CoreBanking coreBanking) { 38 | super(MENU_TITLE, MENU_MAIN, coreBanking); 39 | } 40 | 41 | /** 42 | * Executes the passed menu option. 43 | * 44 | * @param menuOpt The menu option to execute. 45 | */ 46 | protected void executeMenuOption(int menuOpt) { 47 | switch (menuOpt) { 48 | case 1: 49 | ClientsMenu clientsMenu = new ClientsMenu(coreBanking); 50 | clientsMenu.startMenu(); 51 | break; 52 | case 2: 53 | AccountsMenu accountsMenu = new AccountsMenu(coreBanking); 54 | accountsMenu.startMenu(); 55 | break; 56 | case 3: 57 | ComplianceMenu complianceMenu = new ComplianceMenu(coreBanking); 58 | complianceMenu.startMenu(); 59 | break; 60 | case 4: 61 | CoreBankingDataManagementMenu coreBankingDataManagementMenu = 62 | new CoreBankingDataManagementMenu(coreBanking); 63 | coreBankingDataManagementMenu.startMenu(); 64 | break; 65 | case 0: 66 | System.out.println("Bye bye."); 67 | break; 68 | default: 69 | System.out.println("This should never happen... Invalid option: " + menuOpt); 70 | break; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/io/diffblue/corebanking/ui/menu/Menu.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018-2024 Diffblue Limited 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package io.diffblue.corebanking.ui.menu; 18 | 19 | import io.diffblue.corebanking.CoreBanking; 20 | 21 | import java.io.BufferedReader; 22 | import java.io.InputStreamReader; 23 | 24 | public abstract class Menu { 25 | protected final CoreBanking coreBanking; 26 | private final String MENU_TITLE; 27 | private final String[] MENU_ITEMS; 28 | 29 | /** 30 | * Constructor. 31 | * 32 | * @param menuItems The menu items. 33 | */ 34 | protected Menu(String menuTitle, String[] menuItems, CoreBanking coreBanking) { 35 | this.MENU_TITLE = menuTitle; 36 | this.MENU_ITEMS = menuItems; 37 | this.coreBanking = coreBanking; 38 | } 39 | 40 | /** Prints the passed menu. */ 41 | private void printMenu() { 42 | System.out.println("#### " + this.MENU_TITLE + " ####" + "\n"); 43 | for (String s : MENU_ITEMS) { 44 | System.out.println(s); 45 | } 46 | System.out.println(); 47 | } 48 | 49 | /** 50 | * Executes the passed menu option. 51 | * 52 | * @param menuOpt The menu option to execute. 53 | */ 54 | protected abstract void executeMenuOption(int menuOpt); 55 | 56 | /** 57 | * Reads a menu option. 58 | * 59 | * @return A valid menu option. 60 | */ 61 | private int readMenuOption() { 62 | int menuOpt = -1; 63 | 64 | do { 65 | System.out.println("Please select a menu option: "); 66 | 67 | try { 68 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 69 | menuOpt = Integer.parseInt(reader.readLine()); 70 | } catch (Exception e) { 71 | menuOpt = -1; 72 | } 73 | 74 | // Make sure the user selects an available option 75 | if (menuOpt < 0 || menuOpt >= MENU_ITEMS.length) { 76 | System.out.println("Invalid option."); 77 | menuOpt = -1; 78 | } 79 | 80 | } while (menuOpt < 0); 81 | 82 | return menuOpt; 83 | } 84 | 85 | /** Starts the execution of the menu. */ 86 | public void startMenu() { 87 | int menuOpt = -1; 88 | do { 89 | this.printMenu(); 90 | menuOpt = this.readMenuOption(); 91 | this.executeMenuOption(menuOpt); 92 | } while (menuOpt != 0); 93 | } 94 | } 95 | --------------------------------------------------------------------------------