CSSE 220 – Object-Oriented Software Development

Homework 3

Objectives

Practice reading and applying the API documentation, writing Javadocs, and developing using unit tests.

Tasks

  1. Complete the assigned reading for the next session, according to the course schedule.
  2. Complete the assessment exercise over this reading on ANGEL (under Lessons → Assignments).
  3. Programming:
    1. In Eclipse, checkout the JavadocsAndUnitTesting project.

      • Use the SVN Repositories view to check out this project.
    2. We completed this step in class. Add appropriate Javadoc comments to the MoreWordGames class.
    3. We completed this step in class. Create a JUnit 4 Test Case for MoreWordGames.
      • Name your test case class MoreWordGamesTest.
      • Write unit tests for shout, whisper, and holleWerld.
      • Remember, the goal is to write tests that cover “interesting” cases.
    4. Below are the specifications for two additional methods that you will add to MoreWordGames. Use the Java String API documentation to look for helpful methods. For each method below you must:
      1. add a documented method stub to MoreWordGames.java,
      2. add interesting unit tests to MoreWordGamesTest,
      3. implement the method, and
      4. add a line to main to call the method and print the results.
      Here are the methods that you should add:
      • String doubleSpeak(String input): This method returns two copies of the input string, separated by a space. For example:
        • If the input were "moo", the output would be "moo moo"
        • If the input were "My cow is purple", the output would be "My cow is purple My cow is purple"
        • If the input were "" (the empty String), the output would be " " (a single space)
      • String cartBeforeTheHorse(String input): This method returns a string consisting of the last half of the input, followed by the first half, with no intervening space. For example:
        • If the input were banana, the output would be anaban
        • If the input were My cow is purple, the output would be s purpleMy cow i

        You can decide how to handle odd-length input, though one choice lets you avoid using an if-statement. (Recall that integer division truncates the fractional part.) For example:

        • If the input were 1234567, the output can be either 4567123 or 5671234, whichever you choose to implement.
    5. Remember, in all your code:

      • Write appropriate comments:
        • Javadoc comments for public fields and methods.
        • Explanations of anything else that is not obvious.
      • Give self-documenting variable and method names:
        • Use name completion in Eclipse, Ctrl-Space, to keep typing cost low and readability high.
      • Use Ctrl-Shift-F in Eclipse to format your code.
      • Take care of all auto-generated TODO’s.
        • Then delete the TODO comment.
      • Correct ALL compiler warnings.
        • Quick Fix is your friend!

      Here is the grading rubric for this assignment.

  4. Written Problem: Draw your answers to this problem neatly on paper. Clearly label each part of the problem.

    The ObjectReferenceExamples class contains several methods. For each method (except main()):

    1. Draw a box and pointer diagram, like we did in class, showing the result of running the method.
    2. Use your drawings to predict the output of the method.
    3. After you have made your predictions, run the program to check your answers.
    4. If your prediction was wrong, neatly line through it (and your drawing if necessary) and add the correct answer. We won't take off points for such edits, but we want to see your thought process.

Turn-in Instructions

Turn-in your programming work by committing it to your SVN repository. Bring your paper problems to class.