Skip to content

xapn/fizz-buzz-kata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Kata: Fizz-Buzz

Total lines Comments Blank lines TestAsYouThink badge

A little history

Fizz-Buzz is originally a game to help kids to learn the mathematical division by playing with numbers. If a number has a given factor, it is replaced with the matching word: "Fizz" when divisible by 3, "Buzz" when divisible by 5. Later Fizz-Buzz becomes a well-known short programming problem to select developer candidates during job interviews. Fizz-Buzz is also used as an icebreaker for adult groups, in the training, facilitation or Agile background.

Topic

Imagine the scene. You are eleven years old, and in the five minutes before the end of the lesson, your Maths teacher decides he should make his class more “fun” by introducing a “game”. He explains that he is going to point at each pupil in turn and ask them to say the next number in sequence, starting from one. The “fun” part is that if the number is divisible by three, you instead say “Fizz” and if it is divisible by five you say “Buzz”. So now your maths teacher is pointing at all of your classmates in turn, and they happily shout “one!”, “two!”, “Fizz!”, “four!”, “Buzz!”… until he very deliberately points at you, fixing you with a steely gaze… time stands still, your mouth dries up, your palms become sweatier and sweatier until you finally manage to croak “Fizz!”. Doom is avoided, and the pointing finger moves on.

So of course in order to avoid embarassment infront of your whole class, you have to get the full list printed out so you know what to say. Your class has about 33 pupils and he might go round three times before the bell rings for breaktime. Next maths lesson is on Thursday. Get coding!

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Source: CodingDojo.org

Code Kata Boilerplate for Java 8

LoC Files Total lines Comments Blank lines

Use the below badge if you use TestAsYouThink Core to write high-quality tests. TestAsYouThink badge

Getting started

Firstly, either you fork this repository to put all your katas in the same repository, either you create a new repository per kata and push the kata boilerplate into it. Then replace the artifact coordinates used by the build system. Name the code kata too.
Make changes only in the "kata" branch.
You can use this shortened link if needed: tinyurl.com/yyekn5rf.

Tips

You may want to commit with another identifier to publish your code later. Nothing's easier:

git config user.email "public@example.com"
git config user.name "Your Pseudo" # if needed

Take advantage of your IDE shortcuts while resolving any code kata. Download and print the keymap of IntelliJ IDEA. The table below should be very useful to learn, or to learn again, the most important shortcuts.

Theme Must Know Should Know Could Know
General Ctrl + Alt + S to open settings
Ctrl + Shift + A to find action
Editing Ctrl + Space to call basic code completion
Shift + Enter to start new line
Ctrl + Alt + L to auto-indent lines
Ctrl + Y to delete line at caret
Ctrl + Numpad +/- to expand/collapse code block
Ctrl + X to cut current line to clipboard
Ctrl + Q to call quick documentation lookup
Alt + Inser to generate code...
Refactoring Shift + F6 to rename
Ctrl + Alt + M to extract method
Ctrl + Alt + V to extract variable
Ctrl + Alt + F to extract field
Ctrl + Alt + C to extract constant
Ctrl + Alt + P to extract parameter
Navigation Ctrl + N to go to class
Ctrl + Shift + N to go to file
Alt + PageUp/PageDown* to navigate back / forward
Ctrl + B to go to declaration
Ctrl + Alt + B to go to implementation(s)
Ctrl + G to go to line
Compile and Run Shift + F10 / F9 to run / debug
Ctrl + Shift + F10 to run contexte configuration from editor
Usage Search Alt + F7 to find usages
Ctrl + Alt + F7 to show usages

If a shortcut is marked with a '*', it is to configure in the keymap settings of the IDE.

Command Line Interface as a GUI

You can invoke a standalone JAR after building it with the "standalone" Maven profile.

mvn package -Pstandalone # to build it
java -jar target/kata-standalone.jar # to use it

Updating your fork

Update your fork as follows. It is assumed you did not commit in the "master" branch. Otherwise please send me a pull request.

git fetch origin master && git rebase -p --onto origin/master master develop && git branch -f master origin/master

Definition of Done (DoD)

What should be a DoD for the code katas?

  • The kata is done by applying Test-Driven Development (TDD).
  • The code is versioned by applying TDDflow.
  • The path to the solution is discovered according to the Transformation Priority Premise.
  • The path of successive transformations is as simple as possible.
  • The code coverage is greater than 95%.
  • The problem to solve is described in the kata documentation.

License

This code kata boilerplate is distributed under the GNU GPLv3 license. The GPLv3 license is included in the LICENSE.txt file. More information about this license is available at GNU.org.