diff --git a/src/facade/examples/bank/AccountNumberCheck.java b/src/facade/examples/bank/AccountNumberCheck.java new file mode 100644 index 0000000..0835425 --- /dev/null +++ b/src/facade/examples/bank/AccountNumberCheck.java @@ -0,0 +1,19 @@ +package facade.examples.bank; + +/** + * Created by luisburgos on 12/08/15. + */ +public class AccountNumberCheck { + + private int accountNumber = 1234567890; + + public int getAccountNumber() { return accountNumber; } + + public boolean isAccountActive(int accountNumberToCheck){ + if(accountNumberToCheck == getAccountNumber()) { + return true; + } else { + return false; + } + } +} diff --git a/src/facade/examples/bank/BankFacade.java b/src/facade/examples/bank/BankFacade.java new file mode 100644 index 0000000..f4487e5 --- /dev/null +++ b/src/facade/examples/bank/BankFacade.java @@ -0,0 +1,64 @@ +package facade.examples.bank; + +/** + * Created by luisburgos on 12/08/15. + */ +public class BankFacade { + + private int accountNumber; + private int securityCode; + + private AccountNumberCheck accountChecker; + private SecurityCodeCheck codeChecker; + private FundsCheck fundsChecker; + + private WelcomeMessage bankWelcome; + + public BankFacade(int accountNumber, int securityCode){ + + this.accountNumber = accountNumber; + this.securityCode = securityCode; + + bankWelcome = new WelcomeMessage(); + accountChecker = new AccountNumberCheck(); + codeChecker = new SecurityCodeCheck(); + fundsChecker = new FundsCheck(); + + } + + private int getAccountNumber() { return accountNumber; } + + private int getSecurityCode() { return securityCode; } + + public void withdrawCash(double cashAmount){ + + if(canWithdraw(cashAmount)) { + System.out.println("Transaction Complete\n"); + } else { + System.out.println("Transaction Failed\n"); + } + + } + + + public void depositCash(double cashAmount){ + if(canDeposit(cashAmount)) { + fundsChecker.makeDeposit(cashAmount); + System.out.println("Transaction Complete\n"); + } else { + System.out.println("Transaction Failed\n"); + } + } + + private boolean canWithdraw(double cashAmount){ + return accountChecker.isAccountActive(getAccountNumber()) && + codeChecker.isCodeCorrect(getSecurityCode()) && + fundsChecker.haveEnoughMoney(cashAmount); + } + + private boolean canDeposit(double cashAmount){ + return accountChecker.isAccountActive(getAccountNumber()) && + codeChecker.isCodeCorrect(getSecurityCode()); + } + +} diff --git a/src/facade/examples/bank/Client.java b/src/facade/examples/bank/Client.java new file mode 100644 index 0000000..47ae155 --- /dev/null +++ b/src/facade/examples/bank/Client.java @@ -0,0 +1,19 @@ +package facade.examples.bank; + +/** + * Created by luisburgos on 12/08/15. + */ +public class Client { + + public static void main(String[] args) { + + BankFacade accesingBank = new BankFacade(1234567890, 1234); + + accesingBank.withdrawCash(50.00); + accesingBank.withdrawCash(900.00); + accesingBank.depositCash(200.00); + + accesingBank.withdrawCash(900.00); + + } +} diff --git a/src/facade/examples/bank/FundsCheck.java b/src/facade/examples/bank/FundsCheck.java new file mode 100644 index 0000000..51d71b4 --- /dev/null +++ b/src/facade/examples/bank/FundsCheck.java @@ -0,0 +1,36 @@ +package facade.examples.bank; + +/** + * Created by luisburgos on 12/08/15. + */ +public class FundsCheck { + + private double cashInAccount = 1000.00; + + public double getCashInAccount() { return cashInAccount; } + + public void decreaseCashInAccount(double cashWithdrawn) { cashInAccount -= cashWithdrawn; } + + public void increaseCashInAccount(double cashDeposited) { cashInAccount += cashDeposited; } + + public boolean haveEnoughMoney(double cashToWithdrawal) { + + if(cashToWithdrawal > getCashInAccount()) { + System.out.println("Error: You don't have enough money"); + System.out.println("Current Balance: " + getCashInAccount()); + return false; + } else { + decreaseCashInAccount(cashToWithdrawal); + System.out.println("Withdrawal Complete: Current Balance is " + getCashInAccount()); + return true; + } + + } + + public void makeDeposit(double cashToDeposit) { + increaseCashInAccount(cashToDeposit); + System.out.println("Deposit Complete: Current Balance is " + getCashInAccount()); + + } + +} diff --git a/src/facade/examples/bank/SecurityCodeCheck.java b/src/facade/examples/bank/SecurityCodeCheck.java new file mode 100644 index 0000000..1507406 --- /dev/null +++ b/src/facade/examples/bank/SecurityCodeCheck.java @@ -0,0 +1,20 @@ +package facade.examples.bank; + +/** + * Created by luisburgos on 12/08/15. + */ +public class SecurityCodeCheck { + + private int securityCode = 1234; + + public int getSecurityCode() { return securityCode; } + + public boolean isCodeCorrect(int securityCode){ + + if(securityCode == getSecurityCode()) { + return true; + } else { + return false; + } + } +} diff --git a/src/facade/examples/bank/WelcomeMessage.java b/src/facade/examples/bank/WelcomeMessage.java new file mode 100644 index 0000000..8c6420a --- /dev/null +++ b/src/facade/examples/bank/WelcomeMessage.java @@ -0,0 +1,10 @@ +package facade.examples.bank; + +/** + * Created by luisburgos on 12/08/15. + */ +public class WelcomeMessage { + public WelcomeMessage(){ + System.out.println("Welcome to this BANK."); + } +} diff --git a/src/facade/examples/computer/CPU.java b/src/facade/examples/computer/CPU.java new file mode 100644 index 0000000..9169ea6 --- /dev/null +++ b/src/facade/examples/computer/CPU.java @@ -0,0 +1,18 @@ +package facade.examples.computer; + +/** + * Created by luisburgos on 12/08/15. + */ +public class CPU { + public void freeze() { + System.out.println("CPU: Freezing..."); + } + + public void execute() { + System.out.println("CPU: Executing..."); + } + + public void jump() { + System.out.println("CPU: Jumping..."); + } +} diff --git a/src/facade/examples/computer/ComputerFacade.java b/src/facade/examples/computer/ComputerFacade.java new file mode 100644 index 0000000..6864264 --- /dev/null +++ b/src/facade/examples/computer/ComputerFacade.java @@ -0,0 +1,27 @@ +package facade.examples.computer; + +/** + * Created by luisburgos on 12/08/15. + */ +public class ComputerFacade { + + private CPU cpu; + private HardDrive hardDrive; + private Memory memory; + + public ComputerFacade(){ + this.cpu = new CPU(); + this.hardDrive = new HardDrive(); + this.memory = new Memory(); + } + + public void start(){ + System.out.println("STARTING..."); + cpu.freeze(); + memory.load(); + hardDrive.read(); + cpu.jump(); + cpu.execute(); + } + +} diff --git a/src/facade/examples/computer/HardDrive.java b/src/facade/examples/computer/HardDrive.java new file mode 100644 index 0000000..6ff18cc --- /dev/null +++ b/src/facade/examples/computer/HardDrive.java @@ -0,0 +1,11 @@ +package facade.examples.computer; + +/** + * Created by luisburgos on 12/08/15. + */ +public class HardDrive { + public void read() { + System.out.println("HARD DRIVE: Reading..."); + } + +} diff --git a/src/facade/examples/computer/Memory.java b/src/facade/examples/computer/Memory.java new file mode 100644 index 0000000..ee493d4 --- /dev/null +++ b/src/facade/examples/computer/Memory.java @@ -0,0 +1,10 @@ +package facade.examples.computer; + +/** + * Created by luisburgos on 12/08/15. + */ +public class Memory { + public void load() { + System.out.println("MEMORY: Loading..."); + } +} diff --git a/src/facade/examples/computer/User.java b/src/facade/examples/computer/User.java new file mode 100644 index 0000000..036e730 --- /dev/null +++ b/src/facade/examples/computer/User.java @@ -0,0 +1,13 @@ +package facade.examples.computer; + +/** + * Created by luisburgos on 12/08/15. + */ +public class User { + + public static void main(String[] args) { + ComputerFacade computer = new ComputerFacade(); + computer.start(); + } + +}