This site is from a past semester! The current version will be here when the new semester starts.
CS2113/T 2021 Jan-May
  • Full Timeline
  • Week 1 [Mon, Jan 11th]
  • Week 2 [Mon, Jun 21st]
  • Week 3 [Mon, Jun 28th]
  • Week 4 [Mon, Jul 5th]
  • Week 5 [Mon, Jul 12th]
  • Week 6 [Mon, Jul 19th]
  • Week 7 [Mon, Jul 26th]
  • Week 8 [Mon, Aug 9th]
  • Week 9 [Mon, Aug 16th]
  • Week 10 [Mon, Aug 23rd]
  • Week 11 [Mon, Aug 30th]
  • Week 12 [Mon, Sep 6th]
  • Week 13 [Mon, Sep 13th]
  • Textbook
  • Admin Info
  • Dashboards
  •  Individual Project (iP):
  • Individual Project Info
  • iP Upstream Repo
  • iP Code Dashboard
  • iP Progress Dashboard

  •  Team Project (tP):
  • Team Project Info
  • Reference AB3
  • Team List
  • tP Code Dashboard
  • tP Progress Dashboard
  • Java exercises
  • Report Bugs
  • Forum
  • Gitter (Chat)
  • Instructors
  • Announcements
  • Files (handouts, submissions etc.)
  • Tutorial Schedule
  • Java Coding Standard
  • Git Conventions
  • Forum Activities Dashboard
  • Participation Dashboard
  • Week 9 [Mon, Aug 16th] - 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.