Uncategorized

Potato writes code: fizz buzz.

We haven’t been writing for some time recently coz first I was sick and then The Potato left for her well-deserved vacation.

Now we’re all back to reality so it’s time to get back to programming adventure.

And here’s the task I gave to potato:

Please write a code that will execute game of FizzBuzz

What’s FizzBuzz?

FizzBuzz is a counting game where you change a number into a word as follows:

  • Fizz – when the number can be divided by 3
  • Buzz – when the number can be divided by 5
  • FizzBuzz  – when the number can be divided by both: fizz and buzz

For example (starting from 8)

8 Fizz Buzz 11 Fizz 13 14 FizzBuzz

Write a FixxBuzz

Now I’d like you to write a code printing the words for given range of numbers.

Basic FizzBuzz
  1. Create a Gradle Project in Eclipse (File > New > Other… > Gradle Project > choose default options)
  2. Create class and print your FizzBuzz the main method
    • Tip: use if-else statement and a loop (for, while or do while)
Take it further
  • Create separate a Class FizzBuzz that will have your FizzBuzz code.
  • Create method  printFromZero() that will print from 0 to the given last number
    public void printFromZero(int lastNumber)
  • Create method print() that will print your FizzBuzz code for a range of numbers
    public void print(int startNumber, int lastNumber)
  • Create method fizzOrBuzz() that will return you the text you want to print
    public String fizzOrBuzz(int number)

Example solution

There’s no one way to write this code, you can find the example solution in my GitHub repo, exactly here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s