This site is from a past semester! The current version will be here when the new semester starts.
CS2113/T 2020 Aug-Dec
  • Full Timeline
  • Week 1 [Mon, Aug 10th]
  • Week 2 [Fri, Aug 14th]
  • Week 3 [Fri, Aug 21st]
  • Week 4 [Fri, Aug 28th]
  • Week 5 [Fri, Sep 4th]
  • Week 6 [Fri, Sep 11th]
  • Week 7 [Fri, Sep 18th]
  • Week 8 [Fri, Oct 2nd]
  • Week 9 [Fri, Oct 9th]
  • Week 10 [Fri, Oct 16th]
  • Week 11 [Fri, Oct 23rd]
  • Week 12 [Fri, Oct 30th]
  • Week 13 [Fri, Nov 6th]
  • Textbook
  • Admin Info
  • Report Bugs
  • Forum
  • Gitter (Chat)
  • Instructors
  • Announcements
  • Files
  • Tutorial Schedule
  • repl.it link
  • repl.it link (duplicated)
  • Java Coding Standard
  • Git Conventions
  • Forum Activities Dashboard
  • Participation Dashboard

  •  Individual Project (iP):
  • Individual Project Info
  • iP Upstream Repo
  • iP Code Dashboard
  • iP Progress Dashboard

  •  Team Project (tP):
  • Reference AB3
  • Team Project Info
  • Team List
  • tP Code Dashboard
  • tP Progress Dashboard
  • Week 9 [Fri, Oct 9th] - Tutorial

    1 Demo an assertion failure

    • Temporarily edit the tP code to cause an assertion failure. Demo the assertion failure by running the app.
      For example, you can add the following assertion at the start of the main method and then run gradlew run.
      your main class
      ...
      public static void main(String[] args){
      assert false : "dummy assertion set to fail";
      ...
      }
    • Post a screenshot of the assertion failure in the tutorial workspace document.

    2 Exercise: interpret an intermediate level CD

    • 10 minutes With the tutor's guidance, interpret the following class diagram, focusing on the new CD notations that you learned this week.

    Explain the meaning of various class diagram notations in the following class diagram:

    • Some questions you can try to answer:
      1. What does this mean?
      2. What does this mean?
      3. Of the above two, why the lines in one are dashed?
      4. What does this mean?
      5. What's the difference (w.r. t. what it means) between the above and a normal association?
      6. What does this mean?
      7. What's the difference if the diamond is empty?
      8. Can a PR object exist without any Commit objects attached to it?
      9. Can a Commit object exist without a corresponding PR object?
      10. A Student can belong to how many teams?
      11. A Team can have how many Student objects?

    3 Exercise: draw an intermediate level CD

    Question adapted from past exam paper.

    1. before the tutorial Do the following exercise, by hand-drawing the answer.
      Use the following layout:

    Consider the code below:

    public interface Billable {
    void bill();
    }
    public abstract class Item
    implements Billable {
    public abstract void print();
    }
    public class StockItem extends Item {
    private Review review;
    private String name;

    public StockItem(
    String name, Rating rating) {

    this.name = name;
    this.review = new Review(rating);
    }

    @Override
    public void print() {
    //...
    }

    @Override
    public void bill() {
    //...
    }
    }
    public enum Rating {
    GOOD, OK, POOR
    }
    public class Review {
    private final Rating rating;

    public Review(Rating rating) {
    this.rating = rating;
    }
    }
    import java.util.List;

    public class Inventory {
    private List<Item> items;

    public int getItemCount() {
    return items.size();
    }

    public void generateBill(Billable b) {
    // ...
    }

    public void add(Item s) {
    items.add(s);
    }
    }

    (a) Draw a class diagram to represent the code. Show all attributes, methods, associations, navigabilities, visibilities, known multiplicities, and association roles. Show associations as lines.
    (b) Draw an object diagram to represent the situation where the inventory has one item named spanner and a review of POOR rating
    i.e., new Inventory().add(new StockItem("spanner", new Review(Rating.POOR))).

    1. during the tutorial
      • Paste the diagram (take a photo if you drew on paper) in the tutorial workspace document.
      • Discuss answers as guided by the tutor.