Skip to content

Instantly share code, notes, and snippets.


channahnaiman/ Secret

Last active May 23, 2018
What would you like to do?

COMP 271 002 F17: Lab 1


You will work in pairs on various versions of fizz buzz.


An understanding of the following concepts and techniques:

  • Software requirements (K)
  • Combining branching and looping (A)
  • Command-line arguments and basic input/output (C)
  • Using arrays to store and retrieve data (A)
  • Writing testable code and automated testing (A)
  • Refactoring (K)
  • Using lists to store and retrieve data (A)
  • Basic version control (A)

Part 0

Create a GitHub account if you don't have one already. When you submit your assginment, you will submit only your GitHub repository which contains your project for Lab-1.

Part 1

Optionally, form a team of size two (pair) with another classmate. You may work as a pair on the remainder of this lab.

Part 2

Functional requirements: Develop a Java program that behaves as follows ():

  • It expects a natural number (positive integer), n, as its first command-line argument.
  • It determines and prints the fizz buzz sequence up to n, one number per line, on the standard output.

Nonfunctional requirements: Your program should be a Gradle project; You can try to create a new gradle project using IntelliJ IDEA, or you can modify the reference project "build" as shown in lecture videos. Reference project:

Don't forget to "clone" that link, and then remove the .git directory, re-init, etc., and push your own version to your own GitHub account.

Also, since you will most likely want to use the gradle structure from Lab 1's hello-java project for your new FizzBuzz project, you will have to update the build.gradle configurations to match your new class. This is all explained in the Lab walkthrough video.

For example, for n = 17, the program would produce the following output:















fizz buzz



Don't forget to commit and push your work! In addition, tag this commit "lab1-part2". This part receives 0 credit if we cannot find your commit.

Discussion: What would be a really simple solution if n were not an argument, i.e., if it were always 17?

Part 3

Now refactor (change the structure without changing the behavior) of your solution in such a way that it becomes testable:

  • Create an additional method fizzBuzz that takes a numeric argument n. public static String[] fizzBuzzArray(final int n) { … }
  • Change the main method so that it is responsible only for converting the command-line argument to a number and passing it the fizzBuzz method, then printing the resulting array.
  • Now change the method fizzBuzz in such a way that it no longer prints anything but instead stores the resulting data in an array and returns that array.
  • Finally, write a test suite that expresses and tests the correctness of method fizzBuzz for the following values of n:
    • -10

    • -1

    • 0

    • 1

    • 7

    • 17

      You will find this technique useful to compare subranges of arrays: final String[] abc = { "a", "b", "c" };

assertEquals(new String[] { "a", "b" }, Arrays.asList(Arrays.copyOfRange(abc, 0, 2)));

Nonfunctional requirements: use JUnit 4.x.

Don't forget to commit and push your work! In addition, tag this commit "lab1-part3". This part receives 0 credit if we cannot find your commit.

Discussion: How could you have automatically tested your initial solution from part 2?

Part 4

Copy your solution to part 3 and refactor it to use a list from the Java collections library instead of an array. public static List<String> fizzBuzzList(final int n) { … }

Don't forget to commit and push your work! In addition, tag this commit "lab1-part4".

Discussion: What changes between parts 2, 3, and 4, and what stays the same? Does it matter what list implementation you choose? If so, in what way(s)?

Part 5

Create a Markdown document using your preferred tool. For each discussion item, write a brief paragraph with your findings. Add this document to your team repository. Preview it using GitHub itself. (To see an example of Markdown in action, look at the in our reference project.)

Don't forget to commit and push your work! In addition, tag this commit "lab1-part5".


  • GitHub repository including

    • Commits for parts 2-4
    • Markdown document for part 5
  • Individual Sakai submission under "Lab 1"

    • URL of GitHub team repository
    • oo Summary of your individual contributions to this team submission
    • (Your GitHub repository may be an individual one, or one that you have collaborated on with a team member. If you worked as a team, all team members must indicate in the assignment comment box with whom they worked, and must also list the GitHub repo.)
  • Part 2: 10 points

    • 4 points: functional requirements
    • 3 points: nonfunctional requirements - project structure, loop + conditional
    • 3 points: style - variable names, indentation, DRY, comments, etc.
  • Part 3: 10 points (same breakdown as above)

  • Part 4: 10 points (same breakdown as above)

  • Part 5: 10 points

    • Three discussion items
    • Style
    • Formatting
  • TOTAL: 10 points

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment