Question: IN JAVA COMPLETE THIS FIZZ BUZZ PROGRAM Instructions Your goal in this assignment is to implement the FizzBuzz class and have it pass all of
IN JAVA COMPLETE THIS FIZZ BUZZ PROGRAM
Instructions
Your goal in this assignment is to implement the FizzBuzz class and have it pass all of the provided tests. The fizz buzz game is intended to help kids learn about division. Players take turns to count incrementally, replacing any number divisible by three with the word Fizz, and any number divisible by five with the word Buzz. If the current number happens to be a multiple of both three and five the player should say FizzBuzz.
Here are the initial codes for the TWO files.
FIZZBUZZ.JAVA
public class FizzBuzz { private int current; private static final int DEFAULT_START = 1; // TODO: implement parameter-less constructor which should set the current number to the default start public FizzBuzz() { } // TODO: implement parameterized constructor which should set the current number based on the user provided value; if start is less than 1, set current to the default start public FizzBuzz(int start) { } // TODO: implement the getter method that should return the value of current public int getCurrent() { return DEFAULT_START; } // TODO: implement next which should increment current by 1 unit public void next() { } // TODO: override toString which should return the current number as a string, or the words "Fizz", "Buzz", or "FizzBuzz" depending whether the number is a multiple of 3, 5, or both, respectively @Override public String toString() { return ""; } } FIZZBUZZTEST.JAVA
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class FizzBuzzTest { void helperRun1to15(FizzBuzz fb) { assertEquals(1, fb.getCurrent()); assertEquals("1", fb.toString()); fb.next(); assertEquals(2, fb.getCurrent()); assertEquals("2", fb.toString()); fb.next(); assertEquals(3, fb.getCurrent()); assertEquals("Fizz", fb.toString()); fb.next(); assertEquals(4, fb.getCurrent()); assertEquals("4", fb.toString()); fb.next(); assertEquals(5, fb.getCurrent()); assertEquals("Buzz", fb.toString()); fb.next(); assertEquals(6, fb.getCurrent()); assertEquals("Fizz", fb.toString()); fb.next(); assertEquals(7, fb.getCurrent()); assertEquals("7", fb.toString()); fb.next(); assertEquals(8, fb.getCurrent()); assertEquals("8", fb.toString()); fb.next(); assertEquals(9, fb.getCurrent()); assertEquals("Fizz", fb.toString()); fb.next(); helperRun10to15(fb); } void helperRun10to15(FizzBuzz fb) { assertEquals(10, fb.getCurrent()); assertEquals("Buzz", fb.toString()); fb.next(); assertEquals(11, fb.getCurrent()); assertEquals("11", fb.toString()); fb.next(); assertEquals(12, fb.getCurrent()); assertEquals("Fizz", fb.toString()); fb.next(); assertEquals(13, fb.getCurrent()); assertEquals("13", fb.toString()); fb.next(); assertEquals(14, fb.getCurrent()); assertEquals("14", fb.toString()); fb.next(); assertEquals(15, fb.getCurrent()); assertEquals("FizzBuzz", fb.toString()); } @Test void testDefaultStart() { FizzBuzz fb = new FizzBuzz(); helperRun1to15(fb); } @Test void testZeroStart() { FizzBuzz fb = new FizzBuzz(0); helperRun1to15(fb); } @Test void testNegativeStart() { FizzBuzz fb = new FizzBuzz(-1); helperRun1to15(fb); } @Test void testArbitraryStart() { FizzBuzz fb = new FizzBuzz(10); helperRun10to15(fb); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
