- By Emmanuel Valverde
- ·
- Posted Mar 5, 2024 12:05:53 PM
Morning Routine
As a forgetful person, I need to remember my morning routine. Because of this, I have created a program that, depending on the time of day, will tell..
We want to build an ATM machine and the first thing we need to do, is to create the software that will breakdown which bills (notes) and coins to give you when you are trying to make a withdrawal.
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 |
Input:
As a user
I withdraw 434€
Output:
2 bills of 200.
1 bill of 20.
1 bill of 10.
2 coins of 2.
Primitive Obsession and tight couple to the presentation
public interface ATM {
public String withdraw(int quantity);
}
Returning list of DTO or Value Objects
public interface ATM {
public List<Money> withdraw(int quantity);
}
Outside-in
public interface ATM {
public void withdraw(int quantity);
}
The ATM machine has the following distribution of money.
The initial state of any ATM
| Value | Type | quantity of units |
|-------|------|-------------------|
| 500 | bill | 2 |
| 200 | bill | 3 |
| 100 | bill | 5 |
| 50 | bill | 12 |
| 20 | bill | 20 |
| 10 | bill | 50 |
| 5 | bill | 100 |
| 2 | coin | 250 |
| 1 | coin | 500 |
initial ATM state:
| Value | Type | quantity of units |
|-------|------|-------------------|
| 500 | bill | 2 |
| 200 | bill | 3 |
| 100 | bill | 5 |
| 50 | bill | 12 |
| 20 | bill | 20 |
| 10 | bill | 50 |
| 5 | bill | 100 |
| 2 | coin | 250 |
| 1 | coin | 500 |
Input
As a user
I withdraw 1725€
Output
2 bills of 500.
3 bills of 200.
1 bill of 100.
1 bill of 20.
1 bill of 5.
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 bills of 50.
19 bills of 20.
44 bills 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 | 98 |
| 2 | coin | 250 |
| 1 | coin | 500 |
The graphic examples that you see on the kata are not there to be implemented if you don't want to, are there as a reference of how the kata works
As a forgetful person, I need to remember my morning routine. Because of this, I have created a program that, depending on the time of day, will tell..
Inspired by the creative works of Gawain Hewitt: https://gawainhewitt.co.uk/
What do we want to build? We are building a shopping cart for an online grocery shop. The idea of this kata is to build the product in an iterative..
Join our newsletter for expert tips and inspirational case studies
Join our newsletter for expert tips and inspirational case studies