Warning: Outdated Content
This MP is from a previous version of CS 125. Click here to access the latest version.
MP0: Triple Crown
Let’s start hacking! MP0 challenges you to complete three small programming tasks. It also introduces you to the development workflow we’ll use throughout the rest of the semester.
MP0 is due Monday 9/10/2018 @ 7PM. To receive full credit, you must submit by this deadline. Late submissions will be subject to the MP late submission policy.
1. Learning Objectives
The purpose of MP0 is to get you started programming in Java. Specifically, it begins to train you to:
-
initialize and use variables of appropriate types
-
perform simple calculations using integer arithmetic
-
use simple loops and conditional statements
-
translate program descriptions into working code
-
work with test suites as part of your development process
2. Assignment Structure
MP0 consists of three short programs:
-
LCM.java
: computes the least common multiple of two integers -
MinimumOfFirstN.java
: returns the minimum of the first N values of an array of doubles -
Quizzer.java
: computes a score for a short quiz
2.1. MP0 Preparation
Before starting MP0 there are two pieces of setup and preparation to complete:
-
First, download our CS 125 IntelliJ plugin from the JetBrains website. It will make your life a bit easier when working on the MPs.
-
Second, work through our instructions on installing and using Git.
We will provide time during Lab 1 to complete these steps, but you are welcome to go through them beforehand if you are raring to get going.
2.2. Obtaining MP0
Use this GitHub Classroom invitation link to fork your copy of MP0. Once your repository has been created, import it into IntelliJ following our assignment Git workflow guide.
2.3. Your Goal
All three programs need to be completed. The structure of each is similar:
-
Each contains a
main
method that solicits input from the user. You do not need to modify themain
methods, but you may want to read them and try to figure out how they work. -
User inputs are passed to a separate helper function that you are assigned to write. These functions do the heavy lifting for each program: computing the least common multiple (
lcm
), returning the minimum (minimumOfFirstN
), and computing the quiz score (computeScore
). -
Each program includes a test suite:
LCMTest.java
,MinimumOfFirstNTest.java
, andQuizzerTest.java
. The test suite does not test the main method. Instead, it directly tests the method that you are assigned to write. Most test suites contain some simple tests for you to use during development and then a more rigorous grading test suite that earns you points on the MP.
Your goal is to correctly implement the missing methods so that all of the tests pass. Doing so will earn you almost full credit on the assignment—but see the section on style below.
3. How to Approach MP0
Although MP0 may seem daunting at first, do not get discouraged! Focus on identifying what you need to do and understanding the requirements of each function. There is really not a huge amount of code for you to write—our solution adds only several dozen lines, although yours may be slightly longer.
3.1. Understanding What You Need to Do
A core task when approaching any programming assignment or task is to identify what you need to do. For MP0 there are three—and only three—functions that you need to change. Begin by identifying those functions and understanding their requirements. This will go a long way to helping you complete the MP.
3.2. Fixing Initial Errors
Your initial clone of MP0 will receive 0 points.
That’s intentional!
But once you fix a few small bugs you’re score will improve quickly.
In fact, it’s possible to get 40 points for code that doesn’t pass any of the
tests—as long as it compiles and passes the checkstyle
tests.
Use IntelliJ to help you here. It can intelligently identify problems with your MP and guide you toward solutions.
3.3. Test-driven Development
We have provided you with testing suites that you can use to perform iterative test-driven development. You should integrate this process into your normal CS 125 Git workflow. Here’s how that works:
-
Start with one function that you need to write for MP0—say
lcm
inLCM.java
. -
Open
LCM.java
. Run the assignment test suite, which is installed as run configuration "Test MP0". Without changes toLCM.java
, it should fail. -
Begin modifying the
lcm
function. When you think that you have a solution, save you work and re-run the test suite. Better yet, run just one part of the LCM test suite—for example, the test that tries simple inputs. -
If the test suite succeeds, you’re almost done—congratulations!
-
But make sure to run the full grading test suite to ensure that you get full marks! There may be a case that the simple test suites are not trying that you are not handling correctly.
-
If the test suite fails, try to determine why. You may want to run
LCM.java
as a Java application and interact with it to determine what is wrong. Perhaps you are calculating the least common multiple correctly when the first value is greater than the second, but not if the second is greater than the first. Interactive testing can help diagnose these kinds of problems.
In general the fewer lines of code you write before running a test, the better. When you are starting out, it is easy to introduce bugs into your code. Bugs are easiest to catch one-by-one, and so the fewer lines of untested code the more likely you are to identify errors in your logic or implementation.
3.4. Getting Help
The course staff is ready and willing to help you every step of the way! Please come to office hours, or post on the forum when you need help. You should also feel free to help each other, as long as you do not violate the academic integrity requirements.
4. Grading
MP0 is worth 100 points total, broken down as follows:
-
30 points:
LCM.java
-
10 points for submitting code that compiles
-
20 points for passing the test
-
-
30 points:
MinimumOfFirstN.java
-
10 points for submitting code that compiles
-
20 points for passing the test
-
-
30 points:
Quizzer.java
-
10 points for submitting code that compiles
-
20 points for passing the test
-
-
10 points for no
checkstyle
violations
4.1. Submitting Your Work
Follow the instructions from the submitting portion of the CS 125 workflow instructions. Note that the first time you do this you’ll want to pay careful attention to the common submission pitfalls, particularly if your submission doesn’t show up when you think it should.
4.2. Test Cases
You should carefully review the test cases in LCMTest.java
,
MinimumOfFirstNTest.java
, and QuizzerTest.java
.
The MP0 testing suite follows a common pattern where functions are tested
against pre-computed inputs and outputs.
So, for example, when testing MinimumOfFirstNTest.java
, we compute the correct
answer for a small subset of test cases and use this to determine whether your
solution works in all cases.
Automated testing is a hugely important part of modern software development. Just like computers are good at running programs, they are also good at running programs to debug other programs. Independently developing a method and the function that tests it allows the two to support each other. The test may find errors in the method, and, the method may also identify errors in the test.
When possible, we provide you with both simple test cases using a small number of select inputs and exhaustive test cases that use many randomly-generated inputs. The former should be used during iterative development. The latter are used during grading. Note that the simple test cases are not used during grading. So if you pass them but not the full test suite you will not receive credit. The local autograder we provide will be able to help you estimate your score before you submit.
4.3. Autograding
We have provided you with an autograding script that you can use to estimate your current grade as often as you want. The IntelliJ project a run configuration called "Grade MP0" that will run the autograder for MP0.
Unless you have modified the test cases or autograder configuration files, the autograding output should approximate the score that you will earn when you submit. If you modify our test cases or the autograding configuration, all bets are off. You may also lose points if your solution runs too slowly and exceeds the testing timeouts 1.
4.4. Style Points
90 points on MP0 are for correctly implementing the required functions. The other 10 points are for style. Writing readable code according to a style guideline is extremely important, and we are going to help you get into this habit right from the start. Every software development company and most active open-source projects maintain style guidelines. Adhering to them will help others understand and integrate your contributions.
We have configured the checkstyle
plugin to enforce a variant of the
Sun Java coding style.
IntelliJ should naturally generate code that meets this standard.
So you should not have to fight with IntelliJ too much to avoid checkstyle
violations.
However, the checkstyle
plugin does require you to add
Javadoc
comments, and also avoid the use of so-called
magic
numbers.
You may find these requirements a bit annoying at first, but we trust that you
will get used to them.
5. Cheating
Please review the CS 125 cheating policies.
All submitted MP source code will be checked by automated plagiarism detection software. Cheaters will receive stiff penalties—the hard-working students in the class that are willing to struggle for their grade demand it.