# ATM machine # Iteration 1 ## Business rules We want to build an ATM machine and the first thing we want to do it's to create a softaware that calculates the amount of money you are trying to obtain whenever you are trying to do a withdrawal,The software would give you the breakdown of the minimum amount of bills and coins that the ATM would have to give you. The content of the ATM is: ``` | Value | Type | |-------|------| | 500 | bill | | 200 | bill | | 100 | bill | | 50 | bill | | 20 | bill | | 10 | bill | | 5 | bill | | 2 | coin | | 1 | coin | ``` Example: **Input** ``` As a user I withdraw 434€ ``` **Output** ``` 2 bills of 200. 1 bill of 20. 1 bill of 10. 2 coins of 2. ``` ### Possible API for the ATM **Primitive Obsession and tight couple to the presentation** ```java public interface ATM { public String withdraw(int quantity); } ``` **Returning list of DTO or Value Objects** ```java public interface ATM { public List<Money> withdraw(int quantity); } ``` **Outside-in** ```java public interface ATM { public void withdraw(int quantity); } ``` # Iteration 2 ## Business rules By law you only can have 5.000€ on the ATM machine, if anybody tryies to remove more than 5.000€. The ATM machine will throw an error saing that the operation was cancel. Examples: **Input** ``` As a user I withdraw 5.0001€ ``` **Output** ``` The operation was cancel ``` ``` As a user I withdraw 1000€ I withdraw 1000€ I withdraw 1000€ I withdraw 1000€ I withdraw 1001€ ``` **Output** ``` The operation was cancel ``` # Iteration 3 ## Business rules The ATM machine has the following distribution of money - If the ATM has no more bills or coins should try to use other quantities to allow the user to withdraw the amount. ``` | Value | Type | quantity of units | |-------|------|-------------------| | 500 | bill | 2 | | 200 | bill | 3 | | 100 | bill | 4 | | 50 | bill | 12 | | 20 | bill | 20 | | 10 | bill | 50 | | 5 | bill | 100 | | 2 | coin | 250 | | 1 | coin | 500 | ``` ### Examples: **initial ATM state** ``` | Value | Type | quantity of units | |-------|------|-------------------| | 500 | bill | 2 | | 200 | bill | 3 | | 100 | bill | 4 | | 50 | bill | 12 | | 20 | bill | 20 | | 10 | bill | 50 | | 5 | bill | 100 | | 2 | coin | 250 | | 1 | coin | 500 | ``` **Input** ``` As a user I withdraw 1625€ ``` **Output** ``` 2 bills of 500. 1 bill of 20. 1 bill of 10. 2 coins of 2. ``` **ATM state after the output** ``` | Value | Type | quantity of units | |-------|------|-------------------| | 500 | bill | 0 | | 200 | bill | 0 | | 100 | bill | 4 | | 50 | bill | 12 | | 20 | bill | 19 | | 10 | bill | 50 | | 5 | bill | 99 | | 2 | coin | 250 | | 1 | coin | 500 | ``` **Input** ``` As a user I withdraw 1825€ ``` **Output** ``` 4 bills of 100. 12 bill of 50. 1 bill of 20. 44 bill of 10. 1 bill of 5. ``` **ATM state after the output** ``` | Value | Type | quantity of units | |-------|------|-------------------| | 500 | bill | 0 | | 200 | bill | 0 | | 100 | bill | 0 | | 50 | bill | 0 | | 20 | bill | 0 | | 10 | bill | 6 | | 5 | bill | 99 | | 2 | coin | 250 | | 1 | coin | 500 | ```