MP2: String Games

Strings are an important data type in every programming language. While computers understand bits, bytes, and numbers, humans communicate using letters, words, and sentences.

MP2 comprises three string-based programming tasks that will familiarize you with strings and string processing. It is due Friday, September 29th, 2017 @ 5PM. To receive full credit, you must submit by this deadline.

1. Learning Objectives

The purpose of MP2 is to familiarize you with Java strings and string processing. You’ll begin to learn how to:

  1. interpret text as a series of lines, lines as a series of words, and words as a series of characters

  2. use simple looping constructs to iterate over arrays of strings and strings themselves

  3. implement simple state machines

  4. write function definitions

  5. correct Javadoc comments

We’ll also continue to reinforce the learning objectives from MP1.

2. Assignment Structure

MP2 consists of three short programs:

  1. FindLine.java: finds lines in provided multi-line text

  2. ScriptPrinter.java: parses a script and returns lines for a particular actress (or actor)

  3. StrictPalindrome.java: tests whether a provided string is a palindrome

You may find our official MP2 online documentation helpful in understanding what each function is supposed to do.

2.1. Obtaining MP2

Please follow the instructions from MP1. You’ll find MP2 in an MP2 folder in your Subversion home directory.

2.1.1. Recovering in case of accidental deletion

If for some reason you delete you original copy, there are ways to get it back using Subversion 1.

Unlike MP1, we will not provide a tarball. If you delete your MP2 for whatever reason, you will need to recover it using Subversion.

2.2. Your Goal

All programs and incomplete and need work. The structure of each program is similar:

  1. Each contains a main method that solicits input from the user. You do not need to modify the main methods, but you should understand how they work.

  2. User inputs are passed to a separate helper function that you are assigned to write. These functions do the heavy lifting for each program: searching text (printMatchingLines), returning an actress’s lines (printLinesFor), and testing whether a string is a palindrome (isStrictPalindrome).

  3. Each program includes a test suite: FindLineTest.java, ScriptPrinterTest.java, and StrictPalindromeTest.java. The test suite does not test the main method. Instead, it directly tests the method that you are assigned to write.

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. In contrast to last week, you may need to add methods and fix checkstyle errors right out of the box. Until you fix these problems, your initial grade on MP2 will be a zero.

3. How to Approach MP2

All of the MP1 guidelines still apply. In addition, let us provide some new advice for MP2.

3.1. Review java.lang.String

An important part of MP2 is understanding the various methods that you can call on Java strings. The best place to find a complete list is the Javadoc documentation for the Java String type.

You will definitely want to review the list of String methods to find things that might be useful. Specifically, the String methods split, toLowerCase, toUpperCase, startsWith may be useful in completing MP2.

3.2. Documenting Your Work

While comments are not processed by the computer, they are some of the most important things that you will write (and read) as a software developer.

The reason that comments are so important is simple—while the code you write is run by a computer, is is used by other human beings. Regardless of whether a computer can understand what your code is trying to do, if other people cannot you will be in trouble. In the open-source community, nobody will be able to use your contributions—even if they want to. At a job, poorly documented code will get you fired extremely quickly.

So an important job when writing code is documenting it so that others can use it. We will give you practice at doing this on the MPs, and also go over it several times during lab sections. But here are some general guidelines to get you started:

3.2.1. Documentation for packages and functions is extremely important

This is one of the reasons that we are forcing you to write Javadoc comments, since they can be easily used to generate documentation. Here is an example from a previous lab. Well-written documentation makes it possible for others to use your code without understanding your implementation. That is critical to modern software development.

3.2.2. Comments within functions should be used sparingly

On the other hand, comments within your code should be used sparingly. They are not a substitute for writing clear and readable code.

A good way to think about comments in your code is as a chance to explain something unusual that might confuse another person that is reading your code—or, more likely, you!

3.3. Writing Readable Code

Comments and documentation are not a substitute for writing reading code. Think of it this way—documentation is for others that will try to use your code, including collaborators and co-workers. Comments document unusual situations, but are primarily for you, not for others, since you’re the one who’s most likely to have to read (and probably debug) your code.

Readable code is even more important for you and you alone. So treat writing code that is clear and easy to understand as personal and selfish challenge, since it is most likely to benefit you.

3.3.1. Good variable names

One basic aspect of writing good code is good choices of variable names. A good variable name should allow me to understand how it is being used without reading much of the code.

Good variable names depend a lot on context, but one good practice to get in to is to avoid generic names like i, j, index, count, etc. Try more specific names like indexInString, countOfLetters, etc. count could be anything—whereas countOfLetters lets me know more about what is being counted. Keystrokes are cheap, understanding is expensive.

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

MP2 is worth 100 points total, broken down as follows:

  1. 30 points: FindLine.java

    • 10 points for submitting code that compiles

    • 20 points for passing the test

  2. 30 points: ScriptPrinter.java

    • 10 points for submitting code that compiles

    • 20 points for passing the test

  3. 30 points: StrictPalindrome.java

    • 10 points for submitting code that compiles

    • 20 points for passing the test

  4. 10 points for no checkstyle violations

4.1. Test Cases

Like MP1, we have provided exhaustive test cases for each part of MP2. Please review the MP1 testing instructions.

4.2. Autograding

Like MP1, we have provided you with an autograding script that you can use to estimate your current grade as often as you want. The Eclipse project contains a launcher that will run MP2 autograder.

Unless you have modified the test cases or autograder configuration files, the autograding output should equal the score that you will earn when you submit. If you modify our test cases or the autograding configuration, all bets are off.

4.3. Style Points

First, review the style notes from MP1.

However, for MP2 you will have to correct some existing style errors. Please look at the Javadoc comments on other provided functions for examples of how to use the @param and @return tag.

5. Submitting Your Work

Overall you should refer to our instructions for using Subversion. Commit early and often! You only earn credit for the version of your code that is committed to your repository, so ensure that we have your best submission before the deadline.

5.1. Academic Integrity

CS 125 is now CS 124

This site is no longer maintained, may contain incorrect information, and may not function properly.


Created 10/24/2021
Updated 10/24/2021
Commit a44ff35 // History // View
Built 10/24/2021 @ 21:29 EDT