TIC2002 (2019)
  • Full Timeline
  • Week 1 [Aug 12]
  • Week 2 [Aug 19]
  • Week 3 [Aug 26]
  • Week 4 [Sep 2]
  • Week 5 [Sep 9]
  • Week 6 [Sep 16]
  • Week 7 [Sep 30]
  • Week 8 [Oct 7]
  • Week 9 [Oct 14]
  • Week 10 [Oct 21]
  • Week 11 [Oct 28]
  • Week 12 [Nov 4]
  • Week 13 [Nov 11]
  • Textbook
  • Admin Info
  • Report Bugs
  • Forum
  • Announcements
  • File Submissions
  • repl.it link
  • Java Coding Standard
  • Duke repo
  • Week 9 [Oct 14] - Tasks

    1. Implement increments Level-8, A-JavaDoc, A-Gradle optional, A-JUnit

    1 Implement increments Level-8, A-JavaDoc, A-Gradle optional, A-JUnit

    Level-8: Dates and Times

    Level 8. Dates and Times

    Teach Duke to understand dates and times. For example, if the command is deadline return book /by 2/12/2019 1800, Duke understands 2/12/2019 1800 as 2nd of December 2019, 6pm, instead of storing it simply as a String.

    • Minimal: Store deadline dates as a java.time.LocalDate in your task objects. Accept dates in a format such as yyyy-mm-dd format (e.g., 2019-10-15) and print in a different format such as MMM d yyyy e.g., (Oct 15 2019).
    • Stretch goal: Use dates and times in more meaningful ways. e.g., add a command to print deadlines/events occurring on a specific date.

    A code snippet using the LocalDate class:

    import java.time.LocalDate;
    import java.time.format.DateTimeFormatter;
    import java.time.temporal.ChronoUnit;
    
    public class Main {
        public static void main(String[] args) {
            //create dates from strings
            LocalDate d1 = LocalDate.parse("2019-12-01");
            LocalDate d2 = LocalDate.parse("2019-12-02");
            LocalDate d3 = LocalDate.parse("2019-12-02");
            
            //compare dates
            System.out.println(d1.isBefore(d2)); // -> true
            System.out.println(d1.isAfter(d2)); // -> false
            System.out.println(d2.equals(d3)); // -> true
            
            //work with dates
            System.out.println(d1.getDayOfWeek()); // -> SUNDAY
            System.out.println(d1.getMonth()); // -> DECEMBER
            System.out.println(d1.plus(1, ChronoUnit.YEARS));  // -> 2020-12-01
            
            // get today's date and print it in a specific format
            LocalDate d4 = LocalDate.now();
            System.out.println(d4); // -> 2019-10-15
            System.out.println(d4.format(DateTimeFormatter.ofPattern("MMM d yyyy"))); // -> Oct 15 2019
        }
    }
    
    A-JavaDoc: JavaDoc

    A-JavaDoc

         Add JavaDoc comments

    Add JavaDoc comments to the code.

    • Minimal: Add header comments to at least half of the non-private classes/methods.
    • Stretch goal: Add header comments to all non-private classes/methods, and non-trivial private methods.
    A-Gradle: Gradle optional

    A-Gradle

         Automate project builds using Gradle

    Use Gradle to automate some of the build tasks of the project. Refer to the Gradle tutorial at the Duke repo (i.e., the repo you forked from) to find how to set up Gradle for your project.

    • Minimal: Set up gradle so that you can build and run Duke using gradle.
    • Recommended: Set up gradle to run unit tests.
    • Stretch Goal: Use gradle to automate more things in your project.
    A-JUnit: JUnit Testing

    A-JUnit

         Add JUnit tests

    Add JUnit tests to test the behavior of the code.

    Conventions to follow:

    • Add test code in a folder named [project root]\src\test\java\ folder (reason: to follow the convention followed by the project structure so far).
    • Name the test class to match the class being tested (Todo.java can be tested by TodoTest.java), and put it in a package to match. For example,
      • Class being tested seedu.duke.Todo: src\main\java\seedu\duke\Todo.java
      • Test class seedu.duke.TodoTest: src\test\java\seedu\duke\TodoTest.java

    Requirements:

    • Minimum: More than two test methods, preferably targeting more than one class (if you have multiple classes)
    • Stretch goal: test methods to target all public methods of all classes

    Adding JUnit support to your project: As JUnit is a third-party library, you need to add support to it specifically in your project.

    1. Add a folder named [project root]\src\test\java\ (you may have to do this outside of Intellij)
    2. Go to Intellij and add a new module to the project as follows.
      1. FileNewModule From Existing Sources ...
      2. Choose the [project root]\src\test\ (not the java) folder.
      3. In the next screen, select Create module from existing sources
      4. Keep clicking Next until the process is complete
    3. In the Project panel of Intellij, expand the newly-created test module, right-click on the java folder inside it, and choose Mark Directory asTest Source Root (that will make the folder turn to green color).
    4. Now, create a class inside the java folder and type @Test inside it. A code example given below.
      Note: If you are using packages, create this class in a matching package (to test duke.Duke class, create a duke.DukeTest i.e., in src\test\java\duke\DukeTest.java).
      public class DukeTest {
          @Test
      }
      
    5. Note how the @Test turn to red because Intellij (not having JUnit support yet) does not understand it. But it will pop up a hint, asking if you want to add support for JUnit. Select Add JUnit 5.* to classpath.
    6. In the dialog that pops up, you can optionally tick the Sources, JavaDocs and Annotations boxes. After that, click OK to add the JUnit 5 to the project dependencies.
    7. To check if JUnit integration is working as expected,
      1. Add a dummy test method to the class e.g.,
        import org.junit.jupiter.api.Test;
        
        import static org.junit.jupiter.api.Assertions.assertEquals;
        
        public class DukeTest {
            @Test
            public void dummyTest(){
                assertEquals(2, 2);
            }
        }
        
      2. Run the test (right-click on the class and choose Run DukeTest.
    8. To be able to refer to Duke from DukeTest class, you need to add main module as a dependency of the test module you just created.
      • Option 1: When you add a reference to the Duke inside the DukeTest, Intellij will flag it as an error and will give you an option (i.e., in the bulb icon that pops up) to add the main module as a dependency.
      • Option 2: Follow the info here to add the dependency yourself.

    Refer to the Gradle tutorial at the Duke repo (i.e., the repo you forked from) to find how to use JUnit via Gradle.

    A-Gradle

         Automate project builds using Gradle

    Use Gradle to automate some of the build tasks of the project. Refer to the Gradle tutorial at the Duke repo (i.e., the repo you forked from) to find how to set up Gradle for your project.

    • Minimal: Set up gradle so that you can build and run Duke using gradle.
    • Recommended: Set up gradle to run unit tests.
    • Stretch Goal: Use gradle to automate more things in your project.