$29
Overview
For this project, you will need to install and configure Eclipse. You will learn the standard procedure for completing a programming project, testing your code, and submitting it. In this and all future projects, you are provided with starter code, and your task is to complete it according to the project descriptions. We strongly suggest you start this project as early as possible so that you can fix any Eclipse- or grader-related problems well before the deadline. Do not wait until the due date to tell us you don’t understand something, as our ability to help you will be minimal.
Learning Goals
To install the Eclipse integrated development environment (IDE). To import an Eclipse project into the Eclipse IDE.
To write and run Java code in the Eclipse IDE. To run JUnit tests in the Eclipse IDE.
To export a Java project from Eclipse and submit it to the autograder.
General Information [Common]
Reminder: Copying partial or whole solutions, obtained from other students or elsewhere, is academic dishonesty. Do not share your code with your classmates, and do not use your classmates’ code. If you are confused about what constitutes academic dishonesty you should re-read the course policies. We assume you have read the course policies in detail and by submitting this project you have provided your virtual signature in agreement with these policies.
For some projects, it may be useful for you to write additional java files. Any java file you write MUST be placed in the provided src directory of your Eclipse project.
When submitting your project, be sure to remove all compilation errors. Any compilation errors will cause the autograder to fail to run, and consequently you will receive a zero for your submission. No Exceptions!
In the test directory, we provide several JUnit tests that we refer to as the public tests. We recommend you run the tests often and use them as starting points to test your project. In addition, some of the java files come with their own main functions. You can run them as Java applications to interact with the project.
Be aware that the autograder will use a more comprehensive set of tests (referred to as private tests) to grade your project. These tests are hidden from you. We recommend that you think about possible test cases and add new @Test cases to your public test files as part of your programming discipline. In particular, you should consider:
Do your methods handle edge cases such as integer arguments that may be positive, negative, or zero. Many methods only accept arguments that are in a particular range.
Does your code handle cases such as when an array or list is empty, or has reached full capacity?
More complex tests will be project-specific. To build good test cases, think about ways to exercise methods. Work out the correct result for a call of a method with a given set of parameters by hand, then add it as a test case.
Problem 1
Download the Starter Code
Download the provided starter code (“fizzbuzz-student.zip”) for this project and save it somewhere where you can find it. You do not need to unzip it—when importing it, Eclipse will handle the unzipping for you.
Install the Eclipse Development Environment
All the projects in this course use the Eclipse Integrated Development Environment (IDE). The latest version is avail-able at http://www.eclipse.org/downloads/. If you have an older version of Eclipse installed, it likely still works. We do recommend you to install the latest version of Eclipse though, as the starter code hasn’t been tested with older version. To do so, you can remove the older version of Eclipse and install the latest version.
Depending upon your operating system, you might need to install a Java Development Kit (JDK). You should use the Standard Edition, version 8, sometimes abbreviated as the Java SE8 JDK. The latest version of this JDK is available at http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151. html. Accept the license agreement and download the appropriate version for your operating system.
If you encounter problems with the Eclipse installation it is possible that you downloaded and installed Java 8 after installing Eclipse. The symptom is that the project will show several items under the Problems tab (The project cannot be built until build path errors are resolved. and Unbound classpath container: JRE System Library [JavaSE-1.8] in project xxx). Many items in the source will show a red underline. The solution is to: 1) make sure JDK 8 is installed;
open Eclipse, go to Preferences, expand the Java items on the left, and select Installed JREs; 3) click the Search...
button to add the Java 8 JRE, and close the Preferences window.
Import the Starter Code into Eclipse
Open the Eclipse Application
You will be asked to specify a workspace location. This is a directory where all of your Eclipse projects can be stored. You can use one workspace throughout this class (and you can switch the workspace later if needed). If you are opening Eclipse for the first time, you may see a welcome screen with links to instructions, tutorials, etc. You are welcome to read these, but eventually you should click on the upper right: there is a button that will take you to the Workbench, the standard view for working in Eclipse.
Import the Starter Code
Choose “File ! Import” from the menu. A window will come up so you can choose how to import. Select “General” and within that, “Existing Projects into Workspace.” (It may seem strange, but do not choose “Archive File.”) Then click “Next”. Choose the radio button for “Select archive file” and locate the file you downloaded. Then click “Finish”. You should see a fizzbuzz-student Java project in the Package Explorer window on the left. Click on the project to reveal the content and subfolders of this project.
Make the support Directory Read-Only
The support folder contains support and utility code, and you should not modify or add anything in this folder. To help ensure that you do not change anything there, we suggest that you set the support folder read-only. You can do this by right-clicking on it in the Package Explorer, choosing “Properties” from the menu, then under “Resource”, uncheck the Owner’s “Write” permission, and finally click on the “OK” button. A dialog box will show with the title “Confirm recursive changes”, and you should click on the “Yes” button.
You should see three Java source files among the directories:
File
Location
Description
FizzBuzz.java
src
The FizzBuzz class is defined here.
FizzCommander.java
support
A command-line program to drive FizzBuzz.
FizzBuzzTest.java
test
Public tests for FizzBuzz.
The FizzBuzz Game
In this project, you will complete the code in FizzBuzz.java to implement the FizzBuzz game. FizzBuzz is a counting game (https://en.wikipedia.org/wiki/Fizz_buzz) with many variations. If you’ve seen this
game before (for example, 190D’s first programming project is similar), please read carefully because our game below is different. To begin, the players agree on a fizz number and a buzz number, both single-digit integers between 1 and
The players then take turns saying the fizzbuzz value for each successive integer starting from 1. The rules are:
If the integer is divisible by the fizz number, or if it contains the digit fizz number, you must say ‘fizz’;
If the integer is divisible by the buzz number, or if it contains the digit buzz number, you must say ‘buzz’; However, if both the above (i.e. fizz and buzz) conditions are true, you must say ‘fizzbuzz’;
If none of the above conditions is true, say the integer itself.
For example, if the fizz number is 3, and the buzz number is 4, then the first twenty fizzbuzz values are:
1, 2, fizz, buzz, 5, fizz, 7, buzz, fizz, 10, 11, fizzbuzz, fizz, buzz, fizz, buzz, 17, fizz, 19, buzz
Note that the fizzbuzz value of 13 is ‘fizz’, because it contains the digit 3 (even though 13 is not divisible by 3). Similarly: the fizzbuzz value of 31 is ‘fizz’; however, that of 32 is ‘fizzbuzz’ because 32 both contains the digit 3 and is divisble by 4, thereby meeting both the fizz and buzz conditions.
Hints: think for a moment how you should write down Java code to test these conditions, and return the correct fizzbuzz value as a String. First, it is fairly straightforward to test if an integer is divisible by a another integer (how would you do so?). Next, think about how to check if an integer contains a specific digit? For example, 13, 31, 321, 333 all contain digit 3. How do you check this condition? There are several potential solutions. Some of you may be tempted to convert the interger to a string and then check if the string contains that digit. We would strongly recommend you to use a simpler solution that requires only integer operations and does not use strings at all. For example, given a number x, what integer operation do you use to get its last digit? What about the second to last digit?
Using Eclipse
Running the starter code
Under support, choose the FizzCommander.java file, then click the green play button in the top row of the Eclipse window, or choose “Run” from the Run menu. A console will appear in the bottom of the Eclipse window. Enter two number, such as 3 4 (separate by space), and press Enter, you will see the results of the starter code.
Testing the code
Next, choose FizzBuzzTest.java in the Package Explorer and run it using the play button. The package explorer on the left will switch to a JUnit pane, which will show the testing output. You should see several tests, and most (or all) of them will fail because the code needs to be completed by you. Familiarize yourself with the testing interface.
The failed test indicates that some methods in the starter code aren’t returning correct values. If you select / double click each failed test, you should see detailed information under Failure Trace (you may have to resize the JUnit pane to see the full message). JUnit tests work by checking that the expected result of a method call equals the actual result. For example, if a test expects the result of ThreeFour.getValue(12) to be fizzbuzz, and the output of your code produces 12, then the test fails. Since the tests given to you are public, you can check exactly what values it’s testing with, and what’s the expected output.
What You Need to Do
Go to the declaration of getValue(); you can do so by right-clicking on it and selecting “Open Declaration”, or by double-clicking on FizzBuzz.java in the Package Explorer and scrolling to it. What you need to do is to correct the implementation of the getValue() method. Obviously, the correct solution is not merely to make the function
Problem 1 continued on next page. . . Page 5 of 6
FizzBuzz Problem 1 (continued)
return "fizzbuzz" when n == 12. Instead, you should revise the code so that the function will return the correct result for any n, and any fizz and buzz numbers.
In addition, you need to correct the implementation of the getValues() method, which returns an array of fizzbuzz values for a given range of integers. This method should internally call the getValue() method to compute the fizzbuzz value of a single integer, and store it to an array that is to be returned in the end.
When grading your program, we will test both getValue() and getValues() with other fizz and buzz numbers. Our test cases will obey the constraints described in this project (e.g. the fizz number and buzz number are always between 1 and 9), but are otherwise unconstrained (e.g. they can be equal to each other).
Debugging Tips
While JUnit tests can tell you when your output differs from the expected result, it doesn’t directly tell you how to fix the code. You should practise using debugging tools. For example, to check a variable’s value at a specific line of code, you can set breakpoints and run a program in Debug mode; you can step into or step over a method call; you can also use the good old println debug. Google ‘Eclipse debug tutorial’ to learn about these debugging tools.
Export and Submit [Common]
When you have completed this project, you should export an archive file containing the entire Java project. To do this, click on the fizzbuzz-student project in the package explorer. Then choose “File ! Export” from the menu. In the window that appears, under “General” choose “Archive File”. Then choose “Next” and enter a destination for the output file. Be sure that the project is named fizzbuzz-student (otherwise you may be exporting the wrong project!). Save the exported file with the zip extension.
Once you have the zip file ready, you can submit it to the online autograder (Gradescope). Please see the course website and/or documentation explaining how to use the online autograder. If you have any questions please be prompt in asking the course staff before it is too late to submit your solution. If you encounter any errors that look like the autograder failed and not your project, please let the instructors know.
Page 6 of 6