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: read Big Java Chapters 3 and 4(The course schedule will list the reading to be completed before each session, and also discuss some sections to especially focus on) As you read, see if you can answer the self-check questions. If there is something you do not understand, make note of it so you can ask about it. This is the biggest single-session reading assignment of the course. You have four days between Session 3 and Session 4. Read a few sections of the textbook  each day, and this should not be a problem. Put it all off until the day before Session 4, and it will be a big burden!
  1. Edit the Big Java Review Wiki on ANGEL, adding answers (3 stars each) for the review exercises from chapters 3 and 4. Be sure to carefully follow the posted (on the wiki) instructions for doing this.
  2. Programming:
    1. Your programming work for this assignment must be done in the JavadocsAndUnitTesting project inside Eclipse. Use Eclipse's SVN Repository Exploring perspective (or the Repository view) to check out this project, then switch back to the Java perspective.

    2. (1 point) Add appropriate Javadoc comments to the MoreWordGames class.
    3. (2) Create a  JUnit 4 Test Case class for MoreWordGames.
      • Name your test case class MoreWordGamesTest.
      • Write unit tests for shout, whisper, and holleWerld. Use the existing Unit tests in the project as examples.
      • Remember, the goal is to write tests that cover “interesting” cases.
    4. (8) 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 a string consisting of two copies of the input string, separated by a space. For example, if the input were "moo", the output would be "moo moo"
      • 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. 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.)
    5. (6) I have provided the outline of  a simple Java class called  Static Functions that has stubs for the following two static methods. Note that each method must return a value. Neither method should print anything. I have also provided another class that contains Unit tests to test the two methods once you have written them. 

      • public static int maxOfThree (int a, int b, int c)
        returns the largest number that is a value of one of the three parameters. In addition to writing this method, you should add some unit tests in which the values of a, b, and c are not all distinct.
      • public static int monthsToReach(double target, double monthlyDeposit, double annualInterestRate)

        A savings account starts with a zero balance on the first day of one month. On the first day of each subsequent month, interest is calculated on the current balance and added to the account, based on 1/12 of the annual interest rate. Then monthlyDeposit is added to the account. This continues each month until the first month in which the balance reaches or goes beyond target. This method returns the number of the months it takes for the balance to equal or exceed the value of target.

        For example, the call monthsToReach (30000, 500, 0.05) represents a monthly deposit of $500 and an annual interest rate of 5%, asking how long it will take to accumulate $30,000.00. The method returns 54 in this case (recall that it does not print anything). The simpler unit tests I provided should also help your understanding of how the parameters are used.

  3. (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, you may neatly line through it (and your drawing if necessary) and add the correct answer.

Turn-in Instructions

We will grade your Wiki contributions using ANGEL. Turn-in your programming work by committing it to your SVN repository by 8:05 on the day of Session 4.  Bring your answer to the written problem to the Session 4 class.