Exercise: Interactive Fizz Buzz

Write a console program that lets the user enter a number and then uses the following rules to determine what to print:

The program should continue to ask for numbers until the user enters 0.

If the user enters a number smaller than 0, the program should print an error message and ask the user for a new number.

After the user entered 0, the program should print out how many times "fizz", "buzz", and "fizz buzz" were printed.

Your program output should look exactly like this (user input in green):

Enter a number (0 to exit): 1
1
Enter a number (0 to exit): 3
fizz
Enter a number (0 to exit): 5
buzz
Enter a number (0 to exit): 15
fizz buzz
Enter a number (0 to exit): -1
Your number must be 0 or larger. Try again.
Enter a number (0 to exit): 6
fizz
Enter a number (0 to exit): 99
fizz
Enter a number (0 to exit): 23
23
Enter a number (0 to exit): 0
Thanks for playing!
fizz count: 3
buzz count: 1
fizz buzz count: 1

Hand in instructions

  1. Make sure your program runs correctly.
  2. Follow Java naming conventions of variables.
  3. Make sure your program is well-formatted.
  4. Hand in your program by uploading Main.java to Moodle.