Skip to content

Commit 26b79b1

Browse files
author
Julien Letrouit
committed
Translation of the first exercise of AboutInterfaces in french.
1 parent f7a5dc7 commit 26b79b1

3 files changed

Lines changed: 56 additions & 53 deletions

File tree

src/main/java/bonuses/english/AboutInterfaces.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class AboutInterfaces {
3535
*
3636
* It doesn't matter whether you get a baseball bat or a hammer - as long as it implements your three conditions, you're good.
3737
*
38-
* In Java, you sometimes need an object of a class you do not care, but which implements "conditions": one or more specific methods.
39-
* We can see the interface as a kind of contract that an object would respect, by the object having implemented the methods listed in the contract.
38+
* In Java, you often need an object with specific methods, whatever its class is.
39+
* An interface as a kind of contract that an object would respect, by the object implementing the methods listed in the contract.
4040
*
4141
* For example, in a game where the situation above would happen, you could create the following interface:
4242
*
@@ -54,24 +54,24 @@ public class AboutInterfaces {
5454
* public class Sword implements Weapon {
5555
*
5656
* // Since Sword implements Weapon, it must implement the hit method.
57-
* @Override // This strange annotation means the method is defined elsewhere (in our interface)
57+
* @Override // This strange annotation tells Java the method is defined elsewhere (in our interface)
5858
* public void hit(Monster monster) {
5959
* // Some code computing and applying damage to the monster, applying some tear and wear on the weapon, etc...
6060
* }
6161
*
6262
* }
6363
*
64-
* Now, the code in hit() maybe complicated but it does not matter: it follows the contract of the interface, and you can call it.
64+
* Now, the code in 'hit()' maybe complicated but it does not matter: it follows the contract of the interface, and you can call it.
6565
* For example, you could create an object allowing you to hit a zombie with the following code:
6666
*
6767
* Monster zombie = ...; // Code getting the object for the zombie in the middle of the room
68-
* Weapon tossedWeapon = new Sword(); // or new Hammer() or new Axe() or new WhateverImplementsWeapon()
68+
* Weapon tossedWeapon = new Sword(); // or 'new Hammer()' or 'new Axe()' or 'new WhateverImplementsWeapon()'
6969
* tossedWeapon.hit(zombie); // use the Weapon interface
7070
*
71-
* Notice the type of the variable 'tossedWeapon': it is a Weapon, not a Sword. Interfaces, like classes, are types you can use for declaring variables, fields, and parameters.
72-
* Because Sword implements Weapon, Java considers that a Sword object _is_ a Weapon. Having variables and parameters using the interface type allows you to work with any object implementing that interface.
71+
* Notice the type of the variable 'tossedWeapon' is a 'Weapon', not a 'Sword'. Interfaces, like classes, are types you can use for your variables, fields, and parameters.
72+
* Because 'Sword' implements 'Weapon', Java considers that a 'Sword' object _is_ a 'Weapon'. Having variables using the interface type allows it to take values from objects from multiple classes, as long as they all implement the interface.
7373
*
74-
* Take a look at the bonuses.teachingmaterial.Combining interface. It defines a method which can be implemented in various ways.
74+
* Take a look at the 'bonuses.teachingmaterial.Combining' interface. It defines a method which can be implemented in various ways.
7575
* This exercise is about implementing that interface in 2 ways.
7676
*
7777
* -------------------------------

src/main/java/bonuses/french/AboutInterfaces.java

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,82 +8,82 @@
88

99
public class AboutInterfaces {
1010
/**
11-
* # First interface implementations
11+
* # Première implémentations d'interface
1212
*
13-
* Write a class 'numbers.AddNumbers' which implements interface 'bonuses.teachingmaterial.Combining'.
14-
* The implementation of the combine() method should return the 2 numbers added together.
15-
* Write a class 'numbers.MultiplyNumbers' which also implements interface 'bonuses.teachingmaterial.Combining'.
16-
* This implementation of the combine() method should return the 2 numbers multiplied together.
13+
* Écrit une classe 'numbers.AddNumbers' qui implémente l'interface 'bonuses.teachingmaterial.Combining'.
14+
* L'implémentation de la méthode 'combine()' devrait retourner les 2 entiers ajoutés l'un à l'autre.
15+
* Écrit une classe 'numbers.MultiplyNumbers' qui implémente l'interface 'bonuses.teachingmaterial.Combining'.
16+
* L'implémentation de la méthode 'combine()' devrait retourner les 2 entiers multipliés l'un par l'autre.
1717
*
1818
* --------- TIPS --------------
1919
*
20-
* Consider the following situation:
20+
* Considère la situation suivante:
2121
*
22-
* You are in the middle of a large, empty room, when a zombie suddenly attacks you.
23-
* You have no weapon.
24-
* Luckily, a fellow living human is standing in the doorway of the room.
25-
* "Quick!" you shout at him. "Throw me something I can hit the zombie with!"
22+
* Tu es au milieu d'une grande pièce vide, quand un zombie t'attaque soudainement.
23+
* Tu n'as pas d'arme.
24+
* Par chance, un frêre humain vivant est debout dans le cadre de porte de la pièce.
25+
* "Vite!" lui crie tu. "Envoie moi quelque chose avec lequel je puisse frapper le zombie!"
2626
*
27-
* Now consider:
28-
* You didn't specify (nor do you care) exactly what your friend will choose to toss; ...But it doesn't matter, as long as:
27+
* Maintenant regardons:
28+
* Tu n'a pas spécifié ce que ton ami va choisir de t'envoyer (et ça ne t'intéresse pas). Ça n'a pas d'importance, tant que:
2929
*
30-
* 1) It's something that can be tossed (He can't toss you the sofa)
31-
* 2) It's something that you can grab hold of (Not a wet soap)
32-
* 3) It's something you can use to bash the zombie's brains out (That rules out pillows and such)
30+
* 1) C'est quelque chose qui est lançable (il ne peut pas te lancer le sofa)
31+
* 2) C'est quelque chose que tu peux attraper (pas un savon mouillé, donc...)
32+
* 3) C'est quelque chose avec laquelle tu peux endommager le cerveau du zombie (cela exclut donc les oreillers, etc...)
3333
*
34-
* It doesn't matter whether you get a baseball bat or a hammer - as long as it implements your three conditions, you're good.
34+
* Cela n'a pas d'importance si tu reçoit une batte de baseball ou un marteau. Tant que les 3 conditions sont respectées, tu es sauvé.
3535
*
36-
* In Java, you sometimes need an object of a class you do not care, but which implements "conditions": one or more specific methods.
37-
* We can see the interface as a kind of contract that an object would respect, by the object having implemented the methods listed in the contract.
36+
* En Java, tu as souvent besoin d'un objet qui posssède certaines méthodes. Et ce, peu importe sa classe.
37+
* Une interface est un contrat qu'un objet peut choisir de respecter, en implémentant les méthodes listées dans le contrat.
3838
*
39-
* For example, in a game where the situation above would happen, you could create the following interface:
39+
* Par exemple, dans le jeu où la situation ci-dessus pourrait arriver, tu pourrait choisir de créer l'interface suivante:
4040
*
4141
* public interface Weapon {
4242
* void hit(Monster monster);
4343
* }
4444
*
45-
* Now, whether your weapon is a sword inflicting 10 damage points, or a knife inflicting only 4 damage points to the monster, the player will be able to hit a monster with it.
45+
* Maintenant, que l'arme en question soit une épée infligeant 10 points de dommage, ou un couteau n'infligeant que 4 points de dommage au monstre, le joueur pourra frapper le monstre avec.
4646
*
47-
* Respecting the contract of a Java interface is called 'implementing the interface'. A class can implement an interface this way:
47+
* Respecter le contrat d'une interface Java s'appelle 'implémenter l'interface'. Une classe peut implémenter une interface de cette manière:
4848
*
49-
* you declare that this class will implement the Weapon interface
49+
* tu déclare que cette class va implémenter l'interface Weapon
5050
* vvvvvvvvvvvvvvvvv
5151
*
5252
* public class Sword implements Weapon {
5353
*
54-
* // Since Sword implements Weapon, it must implement the hit method.
55-
* @Override // This strange annotation means the method is defined elsewhere (in our interface)
54+
* // Comme Sword implémente Weapon, elle doit implémenter la méthode 'hit()'.
55+
* @Override // Cette étrange annotation dit à Java que cette méthode est définie ailleurs (dans l'interface)
5656
* public void hit(Monster monster) {
57-
* // Some code computing and applying damage to the monster, applying some tear and wear on the weapon, etc...
57+
* // Du code qui, par exemple, calcule et applique le dommage, applique de l'usure à l'arme, etc...
5858
* }
5959
*
6060
* }
6161
*
62-
* Now, the code in hit() maybe complicated but it does not matter: it follows the contract of the interface, and you can call it.
63-
* For example, you could create an object allowing you to hit a zombie with the following code:
62+
* Le code dans 'hit()' peut être compliqué ou simple. Cela n'a pas d'importance: il respecte le contrat de l'interface, et donc tu peux l'appeler.
63+
* Par exemple, tu peux créer un objet qui permet de frapper un zombie avec le code suivant:
6464
*
65-
* Monster zombie = ...; // Code getting the object for the zombie in the middle of the room
66-
* Weapon tossedWeapon = new Sword(); // or new Hammer() or new Axe() or new WhateverImplementsWeapon()
67-
* tossedWeapon.hit(zombie); // use the Weapon interface
65+
* Monster zombie = ...; // Code qui récupère d'une façon ou d'une autre un objet représentant le zombie
66+
* Weapon tossedWeapon = new Sword(); // ou 'new Hammer()' ou 'new Axe()' ou 'new WhateverImplementsWeapon()'
67+
* tossedWeapon.hit(zombie); // utilise l'interface Weapon
6868
*
69-
* Notice the type of the variable 'tossedWeapon': it is a Weapon, not a Sword. Interfaces, like classes, are types you can use for declaring variables, fields, and parameters.
70-
* Because Sword implements Weapon, Java considers that a Sword object _is_ a Weapon. Having variables and parameters using the interface type allows you to work with any object implementing that interface.
69+
* Note que le type de la variable 'tossedWeapon' est 'Weapon' et pas 'Sword'. Les interfaces, comme les classes, sont des types que tu peux utiliser pour tes variables, champs, et paramètres.
70+
* Puisque 'Sword' implémente 'Weapon', Java considère qu'un objet 'Sword' _est_ une 'Weapon'. Avoir une variable de type interface permet que cette variable puisse avoir pour valeur des objets de classes différentes, pourvu qu'elles implémentent toutes l'interface.
7171
*
72-
* Take a look at the bonuses.teachingmaterial.Combining interface. It defines a method which can be implemented in various ways.
73-
* This exercise is about implementing that interface in 2 ways.
72+
* Regarde l'interface 'bonuses.teachingmaterial.Combining'. Elle définie une méthode qui peut être implémentée de plusieurs façons.
73+
* Cet exercice a pour but d'implémenter l'interface de 2 façons.
7474
*
7575
* -------------------------------
7676
*
77-
* Expected result:
77+
* Résultat attendu:
7878
*
79-
* The following code:
79+
* Le code suivant:
8080
*
8181
* Combining combining = new AddNumbers();
8282
* System.out.println(combining.combine(3, 4));
8383
* combining = new MultiplyNumbers();
8484
* System.out.println(combining.combine(3, 4));
8585
*
86-
* Should display:
86+
* Devrait afficher:
8787
*
8888
* 7
8989
* 12
@@ -95,7 +95,7 @@ public class AboutInterfaces {
9595
* # Anonymous interface implementation
9696
*
9797
* Write a method 'getAnonymousCombining' which returns an anonymous implementation of 'bonuses.teachingmaterial.Combining'.
98-
* The implementation of the combine() method should return the second number subtracted from the first.
98+
* The implementation of the combine() method devrait retourner the second number subtracted from the first.
9999
*
100100
* --------- TIPS --------------
101101
*
@@ -122,9 +122,9 @@ public class AboutInterfaces {
122122
*
123123
* -------------------------------
124124
*
125-
* Expected result:
125+
* Résultat attendu:
126126
*
127-
* getAnonymousCombining().combine(3, 4) should return -1
127+
* getAnonymousCombining().combine(3, 4) devrait retourner -1
128128
*
129129
*/
130130

@@ -133,7 +133,7 @@ public class AboutInterfaces {
133133
* # Lambda methods
134134
*
135135
* Write a method 'getLambdaCombining' which returns an lambda method implementing 'bonuses.teachingmaterial.Combining'.
136-
* The implementation of the combine() method should return the first number subtracted from the second.
136+
* The implementation of the combine() method devrait retourner the first number subtracted from the second.
137137
*
138138
* --------- TIPS --------------
139139
*
@@ -207,9 +207,9 @@ public class AboutInterfaces {
207207
*
208208
* -------------------------------
209209
*
210-
* Expected result:
210+
* Résultat attendu:
211211
*
212-
* getLambdaCombining().combine(3, 4) should return 1
212+
* getLambdaCombining().combine(3, 4) devrait retourner 1
213213
*
214214
*/
215215

@@ -251,9 +251,9 @@ public class AboutInterfaces {
251251
*
252252
* -------------------------------
253253
*
254-
* Expected result:
254+
* Résultat attendu:
255255
*
256-
* getIsEven().test(4) should return true
256+
* getIsEven().test(4) devrait retourner true
257257
*
258258
*/
259259

src/main/java/sensei/AboutClassesKoans.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static engine.Assertions.assertNextStdOutLineEquals;
44
import static engine.Assertions.assertNoMoreLineInStdOut;
55
import static engine.Assertions.assertReturnValueEquals;
6+
import static engine.Assertions.assertConstructorIsInvokable;
67
import static engine.Assertions.assertKoanMethodIsInvokable;
78
import static engine.Assertions.assertStaticMethodIsInvokable;
89
import static engine.Localizable.global;
@@ -24,6 +25,7 @@ public class AboutClassesKoans {
2425
public static final List<Koan> koans = List.of(
2526
new Koan(CLASS, CLASSES_AND_PACKAGES)
2627
.beforeFirstTest(
28+
assertConstructorIsInvokable("utils.MathUtils"),
2729
assertStaticMethodIsInvokable("utils.MathUtils", "cube", int.class)
2830
)
2931
.when(callStaticMethod("utils.MathUtils", "cube", 2))
@@ -69,6 +71,7 @@ public class AboutClassesKoans {
6971
),
7072
new Koan(CLASS, AN_OTHER_CLASS_IN_A_NESTED_PACKAGE)
7173
.beforeFirstTest(
74+
assertConstructorIsInvokable("utils.OtherMathUtils"),
7275
assertStaticMethodIsInvokable("utils.OtherMathUtils", "max", int.class, int.class)
7376
)
7477
.when(callStaticMethod("utils.OtherMathUtils", "max", 2, 2))

0 commit comments

Comments
 (0)