CS120 Project 3 lab assignment 2

Today’s lab assignment will help you know when your Project 3 is correct and finished.

Recall that you are to move the functionality of your old main routine into two new methods, formatDate and addToDate. Since you will no longer need to provide a main routine to demonstrate your program, you will be able to use main instead to test your work. In this lab we will step through using main in this way.

  1. First, if you have not yet started on formatDate and addToDate, add stub versions of them to your class — something line
    public static String formatDate(int month, int date) {
      return "TO DO";
    public static String addToDate(int month, int date, int days) {
      return "TO DO";

    If you already have code of your own for these methods, don’t worry about this step.

  2. Next, if you have code in your main method that you want to keep around, rename it to oldMain or something like that.
  3. For your new main method, think of several possible diferent inputs to formatDate and addToDate, and think of what the “right” output for those methods would be in each case.

    For example, we would expect that a call to formatDate(1,10) should return the string

    January 10

    Think of several different input/output pairs. Make sure that you include at least all the cases you saw me use to test your code in Project 1.

  4. For each of these input/output pairs, add a pair of lines to your main routine to print both the expected output for those values, and the actual result from your method.

    For example,

    System.out.println("Expected: January 10");
    System.out.println("  Actual: " + formatDate(1,10));

    This main routine will help you see when your code is working, and what work remains for you to do.

  5. Extra challenge but very useful:
    • Instead of repeating those two lines over and over, add another new method checkExpected so that you can just use:
      checkExpected("January 10", formatDate(1,10));
    • Instead of always printing the expected/actual strings, only print them when they differ. This way your main routine will call your attention only to problems you need to fix, and will not bury them in messages about things that work.

Submission instructions. Submit the single file DateCalc.java to D2L by 8:30am on Wednesday, October 25.

Avoid plagiarism. The course syllabus has further details about our expectations of academic integrity. In particular: You may not copy code from any other source and claim it as your own. You may not share any of your code with any other student for use in completing any of these assignments.

Links to: CS120 homepage