Learn how to use generics using Java.
- OOP knowledge
- Java 11
This kata is about building a gacha machine that we could fill with different type of prize and get them. Gacha machines are quite common in Japan. They are boxes where you introduce a coin and it will give you a random ball that contains some cool minis.
-
First step
- Checkout
first-step
branch and have a look to the code to understand it. Then execute the code. If everything is fine it should be failing. You will have more context about the exercise in the main file. - Implement
GachaMachine#fillPrizes
andGachaMachine#getPrize
methods - If the implementation is ok you should be getting a random superhero in your console. You can always checkout
second-step
branch in case you are stuck.
- Checkout
-
Second step
- Paste the following code under the existing one in your
main
file.
final var pokemonMachine = new GachaMachine(); pokemonMachine.fillPrizes(new PokemonPrize()); final var pokemonPrize = pokemonMachine.getPokemonPrize(); // Should display a random pokemon System.out.println(pokemonPrize);
- Modify your
GachaMachine
to make the code pass. - If the implementation is ok you should be getting a random superhero and a random pokemon in your console. You can always checkout
third-step
branch in case you are stuck.
- Paste the following code under the existing one in your
-
Third step
- You may end up having a lot of code duplication inside your
GachaMachine
, but as you may be thinking this will become quite a tedious task to add methods any time you would like to make your gacha machine compatible with more and more prizes. To avoid it we will change ourGachaMachine
to use generics and make it compatible with any kind of prize. - Checkout this lesson and understand generics
- Make your
GachaMachine
to work using generics. - After coding the solution you should end up having a small
GachaMachine
class using generics and completed this kata! - You can check the final solution checking out
final-code
branch.
- You may end up having a lot of code duplication inside your
Do this exercise pairing with somebody that already knows how generics work, so your pair can solve any question you have about it.