├── .idea ├── .gitignore ├── compiler.xml ├── encodings.xml ├── jarRepositories.xml ├── misc.xml ├── uiDesigner.xml └── vcs.xml ├── README.MD ├── captures └── 1.png ├── pom.xml ├── src └── main │ └── java │ └── net │ └── youssfi │ ├── App.java │ ├── App2.java │ ├── App3.java │ ├── AppFunc.java │ ├── Application.java │ ├── business │ ├── BankAccountService.java │ ├── BankAccountServiceImpl.java │ └── Condition.java │ ├── diagram.uml │ ├── exceptions │ ├── AccountNotFoundException.java │ └── BalanceNotSufficientException.java │ ├── model │ ├── AccountStatus.java │ ├── BankAccount.java │ ├── CurrentAccount.java │ └── SavingAccount.java │ └── utils │ └── DataTransformationUtils.java ├── target └── classes │ └── net │ └── youssfi │ ├── App.class │ ├── App2.class │ ├── App3.class │ ├── AppFunc.class │ ├── Application$1.class │ ├── Application.class │ ├── business │ ├── BankAccountService.class │ ├── BankAccountServiceImpl.class │ └── Condition.class │ ├── exceptions │ ├── AccountNotFoundException.class │ └── BalanceNotSufficientException.class │ ├── model │ ├── AccountStatus.class │ ├── BankAccount.class │ ├── CurrentAccount.class │ └── SavingAccount.class │ └── utils │ └── DataTransformationUtils.class └── test ├── pom.xml ├── src └── main │ └── java │ └── net │ └── youssfi │ └── Main.java └── target ├── classes └── net │ └── youssfi │ └── Main.class └── maven-status └── maven-compiler-plugin └── compile └── default-compile ├── createdFiles.lst └── inputFiles.lst /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /captures/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/captures/1.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | net.youssfi 8 | synthese-poo-java 9 | 1.0-SNAPSHOT 10 | 11 | test 12 | 13 | 14 | pom 15 | 16 | 17 | 17 18 | 17 19 | UTF-8 20 | 21 | 22 | 23 | 24 | 25 | com.fasterxml.jackson.core 26 | jackson-databind 27 | 2.14.1 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/App.java: -------------------------------------------------------------------------------- 1 | package net.youssfi; 2 | import net.youssfi.model.BankAccount; 3 | import net.youssfi.model.CurrentAccount; 4 | import net.youssfi.model.SavingAccount; 5 | 6 | public class App { 7 | public static void main(String[] args) { 8 | 9 | 10 | System.out.println("============================="); 11 | BankAccount account1=null; 12 | account1=new CurrentAccount(); 13 | //account1.setAccountId("123-543"); 14 | account1.setCurrency("MAD"); 15 | account1.setBalance(7600); 16 | printAccount(account1); 17 | 18 | BankAccount account2=new CurrentAccount("MAD",1200,400); 19 | printAccount(account2); 20 | BankAccount account3=new SavingAccount("MAD",1200,3.4); 21 | System.out.println("================"); 22 | account3.setAccountId(account2.getAccountId()); 23 | System.out.println(account2); 24 | System.out.println(account3); 25 | System.out.println("....................."); 26 | if(account2.hashCode()==account3.hashCode()){ 27 | System.out.println("les deux comptes ont le même état"); 28 | } else { 29 | System.out.println("les deux comptes n'ont pas le même état"); 30 | } 31 | account3.setCurrency("USD"); 32 | 33 | if(account2.hashCode()==account3.hashCode()){ 34 | System.out.println("les deux comptes ont le même état"); 35 | } else { 36 | System.out.println("les deux comptes n'ont pas le même état"); 37 | } 38 | System.out.println("....................."); 39 | System.out.println(account2==account3); 40 | System.out.println(account2.equals(account3)); 41 | System.out.println("================"); 42 | 43 | } 44 | 45 | public static void printAccount(BankAccount account){ 46 | System.out.println("*******************************"); 47 | System.out.println("Account ID="+account.getAccountId()); 48 | System.out.println("Balance ="+account.getBalance()); 49 | System.out.println("Status="+account.getStatus()); 50 | System.out.println("Currency ="+account.getCurrency()); 51 | System.out.println(account); 52 | System.out.println(account.hashCode()); 53 | System.out.println(account.equals(account)); 54 | System.out.println("*******************************"); 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/net/youssfi/App2.java: -------------------------------------------------------------------------------- 1 | package net.youssfi; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import net.youssfi.model.BankAccount; 5 | 6 | import java.awt.geom.CubicCurve2D; 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import com.fasterxml.jackson.databind.ObjectMapper; 13 | import net.youssfi.model.CurrentAccount; 14 | import net.youssfi.model.SavingAccount; 15 | 16 | public class App2 { 17 | public static void main(String[] args) throws JsonProcessingException { 18 | 19 | BankAccount [] accounts=new BankAccount[4]; 20 | accounts[0]=new CurrentAccount("USD",5400,500); 21 | accounts[1]=new CurrentAccount("MAD",1290, 4300); 22 | accounts[2]=new SavingAccount("USD",3200,4.6); 23 | accounts[3]=new SavingAccount("MAD",5400,4.3); 24 | 25 | for (BankAccount acc:accounts){ 26 | /* 27 | if(acc instanceof CurrentAccount){ 28 | System.out.println(((CurrentAccount)acc).getType()); 29 | } else if(acc instanceof SavingAccount){ 30 | System.out.println(((SavingAccount)acc).getType()); 31 | } 32 | */ 33 | System.out.println(acc.getType()); 34 | if(acc instanceof SavingAccount){ 35 | System.out.println("Rate="+((SavingAccount)acc).getInterestRate()); 36 | } 37 | if(acc instanceof CurrentAccount){ 38 | System.out.println("Overdraft="+((CurrentAccount)acc).toString()); 39 | } 40 | } 41 | System.out.println("Listes"); 42 | List bankAccountList=new ArrayList<>(); 43 | bankAccountList.add(new CurrentAccount("MAD",5400, 4500) ); 44 | bankAccountList.add(new CurrentAccount("MAD",4300,4300) ); 45 | bankAccountList.add(new SavingAccount("MAD",5400,3) ); 46 | bankAccountList.add(new SavingAccount("MAD",234,4) ); 47 | bankAccountList.add(new CurrentAccount("MAD",65,2) ); 48 | 49 | for (BankAccount acc:accounts){ 50 | System.out.println(acc.getBalance()); 51 | } 52 | 53 | System.out.println("========= Map ========="); 54 | Map bankAccountMap=new HashMap<>(); 55 | bankAccountMap.put("cc1",new CurrentAccount("MAD",4300,43) ); 56 | bankAccountMap.put("cc2",new SavingAccount("MAD",2300,3) ); 57 | bankAccountMap.put("cc3",new CurrentAccount("MAD",3220,4300) ); 58 | bankAccountMap.put("cc4",new SavingAccount("MAD",76,4.3) ); 59 | 60 | BankAccount acc=bankAccountMap.get("cc2"); 61 | System.out.println(acc.toString()); 62 | 63 | for (String key : bankAccountMap.keySet()){ 64 | System.out.println(bankAccountMap.get(key)); 65 | } 66 | System.out.println("============"); 67 | for (BankAccount ba:bankAccountMap.values()){ 68 | System.out.println(toJson(ba)); 69 | } 70 | 71 | 72 | } 73 | 74 | public static String toJson(Object o) throws JsonProcessingException { 75 | ObjectMapper objectMapper=new ObjectMapper(); 76 | return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(o); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/App3.java: -------------------------------------------------------------------------------- 1 | package net.youssfi; 2 | 3 | import net.youssfi.business.BankAccountService; 4 | import net.youssfi.business.BankAccountServiceImpl; 5 | import net.youssfi.business.Condition; 6 | import net.youssfi.exceptions.AccountNotFoundException; 7 | import net.youssfi.exceptions.BalanceNotSufficientException; 8 | import net.youssfi.model.AccountStatus; 9 | import net.youssfi.model.BankAccount; 10 | import net.youssfi.model.CurrentAccount; 11 | import net.youssfi.model.SavingAccount; 12 | import net.youssfi.utils.DataTransformationUtils; 13 | 14 | import java.util.List; 15 | 16 | public class App3 { 17 | public static void main(String[] args) { 18 | BankAccountService bankAccountService=new BankAccountServiceImpl(); 19 | bankAccountService.addRandomData(20); 20 | BankAccount bankAccount1=new CurrentAccount("MAD",32000,100); 21 | bankAccount1.setAccountId("CC1"); 22 | 23 | BankAccount bankAccount2=new SavingAccount("MAD",1000,3.2); 24 | bankAccount2.setAccountId("CC2"); 25 | 26 | bankAccountService.addBankAccount(bankAccount1); 27 | bankAccountService.addBankAccount(bankAccount2); 28 | /* 29 | bankAccountService.getAllAccounts() 30 | .stream() 31 | .map(DataTransformationUtils::toJson) 32 | .forEach(System.out::println); 33 | */ 34 | 35 | BankAccount acc1=null; 36 | BankAccount acc2=null; 37 | try { 38 | acc1 = bankAccountService.getAccountById("CC1"); 39 | acc2 = bankAccountService.getAccountById("CC2"); 40 | System.out.println(DataTransformationUtils.toJson(acc1)); 41 | System.out.println(DataTransformationUtils.toJson(acc2)); 42 | System.out.println("====================="); 43 | bankAccountService.debit(acc1.getAccountId(),2000); 44 | System.out.println(DataTransformationUtils.toJson(acc1)); 45 | System.out.println("====================="); 46 | bankAccountService.transfer("CC1","CC43",3000); 47 | System.out.println(DataTransformationUtils.toJson(acc1)); 48 | System.out.println(DataTransformationUtils.toJson(acc2)); 49 | } catch (AccountNotFoundException | BalanceNotSufficientException e) { 50 | System.out.println(e.getMessage()); 51 | } 52 | System.out.println("***************"); 53 | System.out.println(DataTransformationUtils.toJson(acc1)); 54 | System.out.println(DataTransformationUtils.toJson(acc2)); 55 | System.out.println("==============="); 56 | System.out.println("++++++++++++++++++++++"); 57 | bankAccountService.getSavingAccounts() 58 | .stream() 59 | .map(DataTransformationUtils::toJson).forEach(System.out::println); 60 | ; 61 | System.out.println("Total Balance : "+bankAccountService.getTotalBalance()); 62 | 63 | System.out.println("=============="); 64 | List bankAccountList = bankAccountService.searchAccounts(acc -> acc.getStatus().equals(AccountStatus.ACTIVATED)); 65 | bankAccountList.stream().map(DataTransformationUtils::toJson).forEach(System.out::println); 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/AppFunc.java: -------------------------------------------------------------------------------- 1 | package net.youssfi; 2 | 3 | import java.util.function.Consumer; 4 | import java.util.function.Function; 5 | import java.util.function.Supplier; 6 | 7 | public class AppFunc { 8 | public static void main(String[] args) { 9 | Consumer consumer=(input)-> { 10 | System.out.println(input); 11 | }; 12 | consumer.accept("Hello"); 13 | 14 | Supplier supplier=()-> { 15 | return "azerty"; 16 | }; 17 | System.out.println(supplier.get()); 18 | 19 | Function function=a->a*4; 20 | 21 | System.out.println(function.apply(43)); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/Application.java: -------------------------------------------------------------------------------- 1 | package net.youssfi; 2 | 3 | import net.youssfi.business.BankAccountService; 4 | import net.youssfi.business.BankAccountServiceImpl; 5 | import net.youssfi.exceptions.AccountNotFoundException; 6 | import net.youssfi.model.BankAccount; 7 | import net.youssfi.model.CurrentAccount; 8 | import net.youssfi.model.SavingAccount; 9 | 10 | import java.util.List; 11 | import java.util.function.Consumer; 12 | 13 | public class Application { 14 | public static void main(String[] args) { 15 | BankAccountService bankAccountService=new BankAccountServiceImpl(); 16 | bankAccountService.addBankAccount(new CurrentAccount("MAD",43000,100)); 17 | bankAccountService.addBankAccount(new SavingAccount("MAD",12000,3.5)); 18 | BankAccount bankAccount3=new CurrentAccount("MAD",43000,100); 19 | bankAccount3.setAccountId("CC1"); 20 | bankAccountService.addBankAccount(bankAccount3); 21 | List allAccounts = bankAccountService.getAllAccounts(); 22 | /* 23 | for (int i = 0; i () { 35 | @Override 36 | public void accept(BankAccount account) { 37 | System.out.println(account.toString()); 38 | } 39 | }); 40 | 41 | System.out.println("========"); 42 | allAccounts.forEach(account-> System.out.println(account)); 43 | System.out.println("========"); 44 | allAccounts.forEach(System.out::println); 45 | 46 | System.out.println("----------------------"); 47 | 48 | BankAccount accountById = null; 49 | try { 50 | accountById = bankAccountService.getAccountById("CC6"); 51 | System.out.println(accountById.toString()); 52 | } catch (AccountNotFoundException e) { 53 | System.out.println(e.getMessage()); 54 | e.printStackTrace(); 55 | } 56 | System.out.println("*******************************"); 57 | System.out.println("Suite du programme"); 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/business/BankAccountService.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.business; 2 | import net.youssfi.exceptions.AccountNotFoundException; 3 | import net.youssfi.exceptions.BalanceNotSufficientException; 4 | import net.youssfi.model.BankAccount; 5 | import java.util.List; 6 | import java.util.function.Predicate; 7 | 8 | public interface BankAccountService { 9 | BankAccount addBankAccount(BankAccount account); 10 | List getAllAccounts(); 11 | BankAccount getAccountById(String id) throws AccountNotFoundException; 12 | void addRandomData(int size); 13 | void credit(String accountId, double amount) throws AccountNotFoundException; 14 | void debit(String accountId, double amount) throws AccountNotFoundException, BalanceNotSufficientException; 15 | void transfer(String accountSource, String accountDestination, double amount) throws AccountNotFoundException, BalanceNotSufficientException; 16 | List getSavingAccounts(); 17 | List getCurrentsAccounts(); 18 | double getTotalBalance(); 19 | List searchAccounts(Predicate filter); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/business/BankAccountServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.business; 2 | 3 | import net.youssfi.exceptions.AccountNotFoundException; 4 | import net.youssfi.exceptions.BalanceNotSufficientException; 5 | import net.youssfi.model.AccountStatus; 6 | import net.youssfi.model.BankAccount; 7 | import net.youssfi.model.CurrentAccount; 8 | import net.youssfi.model.SavingAccount; 9 | 10 | import java.nio.channels.AcceptPendingException; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Optional; 14 | import java.util.Random; 15 | import java.util.function.Consumer; 16 | import java.util.function.Function; 17 | import java.util.function.Predicate; 18 | import java.util.stream.Collectors; 19 | import java.util.stream.Stream; 20 | 21 | public class BankAccountServiceImpl implements BankAccountService { 22 | private List bankAccountList=new ArrayList<>(); 23 | @Override 24 | public BankAccount addBankAccount(BankAccount account) { 25 | bankAccountList.add(account); 26 | return account; 27 | } 28 | 29 | 30 | 31 | @Override 32 | public List getAllAccounts() { 33 | return bankAccountList; 34 | } 35 | 36 | @Override 37 | public BankAccount getAccountById(String id) throws AccountNotFoundException { 38 | 39 | // Declarative Approach 40 | return bankAccountList 41 | .stream() 42 | .filter(acc -> acc.getAccountId().equals(id)) 43 | .findFirst() 44 | .orElseThrow(()-> new AccountNotFoundException(String.format("BankAccount %s not found",id))); 45 | 46 | /* 47 | // Imperative Approach 48 | for (BankAccount bankAccount:bankAccountList){ 49 | if(bankAccount.getAccountId().equals(id)){ 50 | return bankAccount; 51 | } 52 | } 53 | throw new AccountNotFoundException("BankAccount not found"); 54 | */ 55 | } 56 | 57 | @Override 58 | public void addRandomData(int size) { 59 | AccountStatus[] values = AccountStatus.values(); 60 | Random random=new Random(); 61 | for (int i = 0; i 0.5){ 64 | bankAccount=new CurrentAccount(Math.random()>0.5?"MAD":"USD",Math.random()*1000000,Math.random()*50000); 65 | bankAccount.setStatus(values[random.nextInt(values.length)]); 66 | } else { 67 | bankAccount=new SavingAccount(Math.random()>0.5?"MAD":"USD",Math.random()*1000000,3+Math.random()*7); 68 | bankAccount.setStatus(values[random.nextInt(values.length)]); 69 | } 70 | bankAccountList.add(bankAccount); 71 | } 72 | } 73 | 74 | @Override 75 | public void credit(String accountId, double amount) throws AccountNotFoundException { 76 | BankAccount accountById = getAccountById(accountId); 77 | accountById.setBalance(accountById.getBalance()+amount); 78 | } 79 | 80 | @Override 81 | public void debit(String accountId, double amount) throws AccountNotFoundException, BalanceNotSufficientException { 82 | BankAccount accountById = getAccountById(accountId); 83 | if(amount>accountById.getBalance()) throw new BalanceNotSufficientException("Balance not sufficient"); 84 | accountById.setBalance(accountById.getBalance()-amount); 85 | } 86 | 87 | // Doit être transactionnelle 88 | @Override 89 | public void transfer(String accountSource, String accountDestination, double amount) throws AccountNotFoundException, BalanceNotSufficientException { 90 | debit(accountSource,amount); 91 | credit(accountDestination,amount); 92 | } 93 | 94 | @Override 95 | public List getSavingAccounts() { 96 | // Declarative Approach 97 | List collect = bankAccountList 98 | .stream().filter(acc -> acc instanceof SavingAccount).collect(Collectors.toList()); 99 | return collect; 100 | /* 101 | // Imperative Approach 102 | List result=new ArrayList<>(); 103 | for (BankAccount acc:bankAccountList){ 104 | if(acc.getType().equals("SAVING_ACCOUNT")){ 105 | result.add(acc); 106 | } 107 | } 108 | return result; 109 | */ 110 | } 111 | 112 | @Override 113 | public List getCurrentsAccounts() { 114 | List collect = bankAccountList 115 | .stream().filter(bankAccount -> false).collect(Collectors.toList()); 116 | return collect; 117 | } 118 | 119 | @Override 120 | public double getTotalBalance() { 121 | return bankAccountList 122 | .stream() 123 | .map(account -> account.getBalance()) 124 | .reduce(0.0,(a,v)->a+v); 125 | /* 126 | double sum=0; 127 | for (BankAccount acc:bankAccountList){ 128 | sum=sum+acc.getBalance(); 129 | } 130 | return sum; 131 | */ 132 | } 133 | 134 | @Override 135 | public List searchAccounts(Predicate filter) { 136 | List result=new ArrayList<>(); 137 | for (BankAccount acc:bankAccountList){ 138 | if (filter.test(acc)){ 139 | result.add(acc); 140 | } 141 | } 142 | return result; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/business/Condition.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.business; 2 | 3 | import net.youssfi.model.BankAccount; 4 | 5 | @FunctionalInterface 6 | public interface Condition { 7 | boolean test(T o); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/diagram.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | JAVA 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | All 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/exceptions/AccountNotFoundException.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.exceptions; 2 | 3 | public class AccountNotFoundException extends Exception { 4 | public AccountNotFoundException(String message){ 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/exceptions/BalanceNotSufficientException.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.exceptions; 2 | 3 | public class BalanceNotSufficientException extends Exception { 4 | public BalanceNotSufficientException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/model/AccountStatus.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.model; 2 | 3 | public enum AccountStatus { 4 | CREATED, ACTIVATED, SUSPENDED, BLOCKED 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/model/BankAccount.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.model; 2 | 3 | import java.util.Objects; 4 | import java.util.UUID; 5 | 6 | public abstract class BankAccount { 7 | private String accountId; 8 | private double balance; 9 | private String currency; 10 | private AccountStatus status; 11 | 12 | public BankAccount(){ 13 | this.accountId= UUID.randomUUID().toString(); 14 | this.status=AccountStatus.CREATED; 15 | } 16 | 17 | public BankAccount(String currency, double initialBalance){ 18 | this(); 19 | this.currency=currency; 20 | this.balance=initialBalance; 21 | } 22 | 23 | public String getAccountId() { 24 | return accountId; 25 | } 26 | 27 | 28 | public void setAccountId(String accountId) { 29 | this.accountId = accountId; 30 | } 31 | 32 | public double getBalance() { 33 | return balance; 34 | } 35 | 36 | public void setBalance(double balance) { 37 | this.balance = balance; 38 | } 39 | 40 | public AccountStatus getStatus() { 41 | return status; 42 | } 43 | 44 | public void setStatus(AccountStatus status) { 45 | this.status = status; 46 | } 47 | 48 | public String getCurrency() { 49 | return currency; 50 | } 51 | 52 | public void setCurrency(String currency) { 53 | this.currency = currency; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "BankAccount{" + 59 | "accountId='" + accountId + '\'' + 60 | ", balance=" + balance + 61 | ", currency='" + currency + '\'' + 62 | ", status=" + status + 63 | '}'; 64 | } 65 | 66 | @Override 67 | public boolean equals(Object acc) { 68 | BankAccount account=(BankAccount) acc; 69 | if(this.accountId==account.accountId){ 70 | return true; 71 | } else { 72 | return false; 73 | } 74 | } 75 | 76 | @Override 77 | public int hashCode() { 78 | return Objects.hashCode(this.accountId)+ 79 | Objects.hashCode(this.balance)+ 80 | Objects.hashCode(this.status)+ 81 | Objects.hashCode(this.currency); 82 | } 83 | 84 | public abstract String getType(); 85 | 86 | public final void print(){ 87 | System.out.println("----------- BANK -----------------"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/model/CurrentAccount.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.model; 2 | 3 | public class CurrentAccount extends BankAccount{ 4 | private double overDraft; 5 | 6 | public CurrentAccount() { 7 | super(); 8 | } 9 | 10 | public CurrentAccount(String currency, double initialBalance, double overDraft) { 11 | super(currency, initialBalance); 12 | this.overDraft = overDraft; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return "Current Account, Overdraft ="+overDraft+super.toString(); 18 | } 19 | 20 | @Override 21 | public String getType() { 22 | return "CURRENT_ACCOUNT"; 23 | } 24 | 25 | public void setOverDraft(double overDraft) { 26 | this.overDraft = overDraft; 27 | } 28 | 29 | public double getOverDraft() { 30 | return overDraft; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/model/SavingAccount.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.model; 2 | 3 | public final class SavingAccount extends BankAccount{ 4 | private double interestRate=2.5; 5 | 6 | public SavingAccount() { 7 | super(); 8 | } 9 | 10 | public SavingAccount(String currency, double initialBalance, double interestRate) { 11 | super(currency, initialBalance); 12 | this.interestRate = interestRate; 13 | } 14 | 15 | public void setInterestRate(double interestRate) { 16 | this.interestRate = interestRate; 17 | } 18 | 19 | public double getInterestRate() { 20 | return interestRate; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "Saving Account , interest rate="+interestRate+","+super.toString(); 26 | } 27 | 28 | @Override 29 | public String getType() { 30 | return "SAVING_ACCOUNT"; 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/youssfi/utils/DataTransformationUtils.java: -------------------------------------------------------------------------------- 1 | package net.youssfi.utils; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | 6 | public class DataTransformationUtils { 7 | public static String toJson(Object o){ 8 | ObjectMapper objectMapper=new ObjectMapper(); 9 | String json = null; 10 | try { 11 | json = objectMapper 12 | .writerWithDefaultPrettyPrinter() 13 | .writeValueAsString(o); 14 | return json; 15 | } catch (JsonProcessingException e) { 16 | return "{}"; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /target/classes/net/youssfi/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/App.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/App2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/App2.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/App3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/App3.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/AppFunc.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/AppFunc.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/Application$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/Application$1.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/Application.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/Application.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/business/BankAccountService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/business/BankAccountService.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/business/BankAccountServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/business/BankAccountServiceImpl.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/business/Condition.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/business/Condition.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/exceptions/AccountNotFoundException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/exceptions/AccountNotFoundException.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/exceptions/BalanceNotSufficientException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/exceptions/BalanceNotSufficientException.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/model/AccountStatus.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/model/AccountStatus.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/model/BankAccount.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/model/BankAccount.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/model/CurrentAccount.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/model/CurrentAccount.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/model/SavingAccount.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/model/SavingAccount.class -------------------------------------------------------------------------------- /target/classes/net/youssfi/utils/DataTransformationUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/target/classes/net/youssfi/utils/DataTransformationUtils.class -------------------------------------------------------------------------------- /test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | synthese-poo-java 7 | net.youssfi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | test 13 | 14 | 15 | 17 16 | 17 17 | UTF-8 18 | 19 | 20 | 21 | 22 | 23 | com.fasterxml.jackson.core 24 | jackson-databind 25 | 2.14.1 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /test/src/main/java/net/youssfi/Main.java: -------------------------------------------------------------------------------- 1 | package net.youssfi; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | System.out.println("Hello world!"); 6 | } 7 | } -------------------------------------------------------------------------------- /test/target/classes/net/youssfi/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohamedYoussfi/back-to-java-oop/f5df1aff723d3af25ac987a80e807ed474ba16b4/test/target/classes/net/youssfi/Main.class -------------------------------------------------------------------------------- /test/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | net/youssfi/Main.class 2 | -------------------------------------------------------------------------------- /test/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Users/mohamedyoussfi/IdeaProjects/synthese-poo-java/test/src/main/java/net/youssfi/Main.java 2 | --------------------------------------------------------------------------------